# Resize script trouble

**URL:** <https://forum.kirupa.com/t/resize-script-trouble/259828>\
**Category:** Uncategorized\
**Created:** [May 9, 2008, 3:51am UTC](https://forum.kirupa.com/t/resize-script-trouble/259828 "2008-05-09T03:51:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bombdigiti](https://avatars.discourse-cdn.com/v4/letter/b/b5ac83/32.png) [@bombdigiti](https://forum.kirupa.com/u/bombdigiti)\
**Post date:** [May 9, 2008, 3:51am UTC](https://forum.kirupa.com/t/resize-script-trouble/259828/1 "2008-05-09T03:51:15Z")

</div>

hey… im just trying to resize an image when it is being uploaded to the db… but i am getting a bunch of random text… wondering what is up? Any help is awesome, thanks

```php

<?php 
$uploadedfile = $_FILES['image']['tmp_name'];
$filetype = $_FILES['image']['type'];
$src = imagecreatefromjpeg($uploadedfile);
list($width,$height)=getimagesize($uploadedfile);
if($height > $width) {
$newwidth=190;
$newheight=($height/$width)*190;
}else{
$newheight=190;
$newwidth=($width/$height)*190;
}
$tmp=imagecreatetruecolor($newwidth,$newheight);
imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
$target_path = "images/".$_FILES['image']['name'];
imagejpeg($tmp,$filename,100);
imagedestroy($src);
imagedestroy($tmp);
$imagename = basename( $_FILES['image']['name']);
$querystring = "INSERT INTO tbl_images(img_id,img_title,img_url,img_cat,img_info) VALUES(NULL,'".$title."','".$url."','".$cat."','".$info."')";
$insertimage = mysql_query($querystring);
/*if(move_uploaded_file($_FILES['image']['tmp_name'], $target_path)) {
header ("Location: http://localhost:8888/portfolio/admin_main.php");
} else{
    echo "There was an error uploading the file, please try again!";
}
*/
?>

```

---

<div class="post-metadata">

**Author:** ![kdd](https://avatars.discourse-cdn.com/v4/letter/k/ecb155/32.png) [@kdd](https://forum.kirupa.com/u/kdd)\
**Post date:** [May 9, 2008, 6:38am UTC](https://forum.kirupa.com/t/resize-script-trouble/259828/2 "2008-05-09T06:38:18Z")

</div>

Bunch of random text where? In the image data? If I’m not mistaken, you cannot create imagejpeg if a gif MIME-TYPE files was uploaded. So, please check that.

---

<div class="post-metadata">

**Author:** ![hl1](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/hl1/32/849_2.png) [@hl1](https://forum.kirupa.com/u/hl1)\
**Post date:** [May 9, 2008, 7:10pm UTC](https://forum.kirupa.com/t/resize-script-trouble/259828/3 "2008-05-09T19:10:09Z")

</div>

You need a line to set the content mime type for browser interpretation.

```php
header('Content-type: image/jpg');

```

Putting that before outputting anything should fix it up.

---

<div class="post-metadata">

**Author:** ![kdd](https://avatars.discourse-cdn.com/v4/letter/k/ecb155/32.png) [@kdd](https://forum.kirupa.com/u/kdd)\
**Post date:** [May 9, 2008, 7:41pm UTC](https://forum.kirupa.com/t/resize-script-trouble/259828/4 "2008-05-09T19:41:44Z")

</div>

That’s for outputting an image, hl. I think he meant random text in image file or something, the question, yet, is not clear.
