I've coded an image resizing function. It works very well for most image types but I've found that there seems to be a problem with progressive jpeg. If I resize my image for a thumbnail size, 50 px of width the result is only a small black square. I've tried with other image types again to be sure everything was right and it's still working fine.

Did you face that problem?

Your help would be greatly appreciated! Thanks in advance :-)

Recommended Answers

All 10 Replies

I've not personally come across that problem but I would suggest starting by looking at the version of PHP, and the version of the GD Library you have installed.


You should find the info in there then check with the php.net website that its fairly up to date, as a starting point.

Member Avatar

What are you using to resize? Include your code.

Thanks for replying, here's what my code looks like

$upload = $_FILES["Image"]["tmp_name"];
$details_type = explode("/", $_FILES["Image"]["type"]);

if($details_type[1] == "jpg" || $details_type[1] == "jpeg" || $details_type[1] == "pjpeg")
$tmp = imagecreatefromjpeg($upload);
elseif($details_type[1] == "png")
$tmp = imagecreatefrompng($upload);
elseif($details_type[1] == "gif")
$tmp = imagecreatefromgif($upload);
list($width,$height) = getimagesize($upload);

$new_height =($height/$width)*$new_width;
$output= imagecreatetruecolor($new_width,$new_height);
imagecopyresized($output, $tmp, 0,0,0,0,$new_width, $new_height, $width, $height);
$img_name = $path."thumb_".$_FILES["Image"]["name"];
imagejpeg($output, $img_name, 100);
Member Avatar

if everything works fine with other extensions, I'm not sure I know what's going on.

However for extension, I'd use this:

$ext = pathinfo($_FILES['Image']['tmp_name'], PATHINFO_EXTENSION);

THat should work no matter what the location of the 'temporary' directory

Does imagejpeg() work no matter what the input extension?
I very rarely use this. Anybody else?

not used gd library for a few years but I'd suggest changing your code and try saving as a png instead to debug/see if you get the same problems. even if png isn't something you want to use it might help you narrow down the problem.

Thanks both for the tips, Kevin I'll try with png tonight.

I've found exactly why it wasn't working. The image I tried to upload was in CMYK, I've converted it with photoshop and now it works perfectly. Internet Explorer doesn't support CMYK but Firefox and Chrome do.

IE can't do something firefox and chrome and safari and opera can do??? shocking ;)

I want a code to check the size of the image before you update to the website. Who can help me

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.