# Making thumbnails with GD Library

**URL:** <https://forum.kirupa.com/t/making-thumbnails-with-gd-library/254801>\
**Category:** Uncategorized\
**Created:** [March 15, 2008, 4:53pm UTC](https://forum.kirupa.com/t/making-thumbnails-with-gd-library/254801 "2008-03-15T16:53:34Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![iNeed\_Help](https://avatars.discourse-cdn.com/v4/letter/i/49beb7/32.png) [@iNeed\_Help](https://forum.kirupa.com/u/iNeed_Help)\
**Post date:** [March 15, 2008, 4:53pm UTC](https://forum.kirupa.com/t/making-thumbnails-with-gd-library/254801/1 "2008-03-15T16:53:34Z")

</div>

I’ve made an upload form that allows you to upload images and I want to use the GD Library to store a thumbnail of the image in the same directory. When I submit the form though it displays the path to the php file in the browser(e.g. [http://localhost/thumbform.php)](http://localhost/thumbform.php%29). I think the problem lies in the line with the “Header”, can someone tell me where I’m going wrong?

```php

<?php    
    if(isset($_POST['submit'])) {        
        // This sets the variables for my posted file & destination directory
        $img_info = $_FILES['img_file'];    
        $img_name = $img_info['name'];
        $img_type = $img_info['type'];
        $tmp_name = $img_info['tmp_name'];
        $img_size = $img_info['size'];
        $destination = "thumbs";
        
        // This is where the file is moved into the destination directory
        $temp_place = $_FILES['img_file']['tmp_name'];
        $move_result = move_uploaded_file($temp_place, $destination."/".$img_name);
        if(!$move_result) {
            die("Upload was not complete.");
        }
    
        // And this is where the thumbnail is meant to be created and then moved to the same directory.
        $img_name = $_POST['img_name'];
        $save = "{$destination}/tn_{$img_name}";
        $file = '{$img_name}';          
        $size = 0.45;
        header('Content-type: image/jpeg') ;
        list($width, $height) = getimagesize($file) ;
        $modwidth = $width * $size;
        $modheight = $height * $size;
        $tn = imagecreatetruecolor($modwidth, $modheight) ;
        $image = imagecreatefromjpeg($file) ;
        imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ;
        imagejpeg($tn, $save, 100) ;
    }
?>

```
