954,580 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Image resizing

Hello,

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 :-)

brainstorm85
Newbie Poster
4 posts since Dec 2011
Reputation Points: 10
Solved Threads: 0
 

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.

phpinfo();


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

kevindougans
Junior Poster
129 posts since Oct 2007
Reputation Points: 13
Solved Threads: 7
 

What are you using to resize? Include your code.

diafol
Rhod Gilbert Fan (ardav)
Moderator
7,792 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
 

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_width=50;
$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);
brainstorm85
Newbie Poster
4 posts since Dec 2011
Reputation Points: 10
Solved Threads: 0
 

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?

diafol
Rhod Gilbert Fan (ardav)
Moderator
7,792 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
 

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.

kevindougans
Junior Poster
129 posts since Oct 2007
Reputation Points: 13
Solved Threads: 7
 

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

brainstorm85
Newbie Poster
4 posts since Dec 2011
Reputation Points: 10
Solved Threads: 0
 

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.

brainstorm85
Newbie Poster
4 posts since Dec 2011
Reputation Points: 10
Solved Threads: 0
 

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

kevindougans
Junior Poster
129 posts since Oct 2007
Reputation Points: 13
Solved Threads: 7
 

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

huongviet
Newbie Poster
3 posts since Dec 2011
Reputation Points: 10
Solved Threads: 1
 
kevindougans
Junior Poster
129 posts since Oct 2007
Reputation Points: 13
Solved Threads: 7
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: