homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

Creating thumbnails with PHP
too much information

 5:19 am on Aug 3, 2010 (gmt 0)

I'm going nuts here. I started a project just over a year ago and had no problems with any of this but now that I'm starting on it again my thumbnail efforts are a constant fail.

To get a clean start on this project again I created a subdomain to work under and I'm not sure if that is my problem.

I want to create three different sized smaller images for every image that a user uploads. I could do this on the fly when the project runs but it would be faster if I could do this once on upload and just pull the correct size when needed.

I've tried phpThumb from Sourceforge, I've tried using the GD library, I've tried using ImageMagik and I've tried the newest version of phpthumb from gxdlabs. None of the methods work.

The most frustrating thing is that the phpThumb setup worked the last time I worked on the project.

Is there a reason that any type of thumbnailing would fail in PHP? I've got my timeout set to 0 and my memory set to 6MB, so I'm at a loss.

Any help would be appreciated.



 9:45 am on Aug 3, 2010 (gmt 0)

can you explain what's the error/reason that failed with the GD library? Is there an error message?

I have no idea about the rest as these are applications bloated IMO.

A straight forward sequence is: file is uploaded in a folder, when the image file is requested the thumbnailer generates the thumbnail file once. Thereafter it simply loads it. So there is no difference in speed with creating the thumbs on upload. In fact if the thumb is never requested it doesn't need to exist.

Some php thumb code that I play around with, uses just few lines for this functionality you described. For a jpg with the GD library imagecreatejpeg, imagejpeg and imagecopyresampled functions should be sufficient. Do these functions work in your server?


 10:55 am on Aug 3, 2010 (gmt 0)

...and my memory set to 6MB

Memory available to PHP? If so, this sounds very low. 64MB would be more usual, even on a shared host. An uncompressed 3mp image is 8.5MB. Although images would ideally be resized to at least a reasonable size before uploading.


 11:12 am on Aug 3, 2010 (gmt 0)

Have you checked your error log?



 4:08 pm on Aug 3, 2010 (gmt 0)

Is there an error message?

Right, **how** is it not working?

In advance, everything you do should have an error trap, this helps answer this question. Add this to the bottom of every script, or as a php include:

function error($errstr) {
echo "<p>Error: $errstr</p>";

Then wherever you do **anything** add a simple or:

$image= new Imagick($path);
$width = $image->getImageWidth() or error("Cannot get image width for $path");

$image->thumbnailImage($newwidth,$newheight) or error("Cannot write image, w: $newwidth h: $newheight");

Since you're having troubles with all the tools, I will venture one guess, it's a path issue, confusion of full server paths and relative paths/urls, similar to the problems here [webmasterworld.com] and here [webmasterworld.com]. It seems to be more common in PHP than other languages.

too much information

 4:58 pm on Aug 4, 2010 (gmt 0)

I like the error trap idea, I didn't think of using something like that. And I haven't checked my error logs yet, but maybe I should.

What I have is a Flash uploader so I can upload multiple files, each file is limited to 1MB in size. Then after the upload is complete Flash calls my PHP script which does some database stuff and creates the thumbnails. The only thing that isn't working is the thumbnail part.

I'm not sure what the problem is because the exact same script works fine on the original domain where I started the project. All of which is on the same server.

I'll check the error logs to see if I can find anything that might help.


 6:25 pm on Aug 4, 2010 (gmt 0)

...each file is limited to 1MB in size.

Note that this is the compressed jpeg filesize. When the image is manipulated/resized in memory it is uncompressed, so a 1MB image will be at least 10+MB uncompressed (quite possibly a lot more) and then there's the added overhead of processing, hence my query about memory above.

too much information

 4:26 am on Aug 5, 2010 (gmt 0)

I gotcha penders, I didn't think of the unzipped file size and I'm not sure that is the problem anyway but I'll try bumping that up.

And about the errors, the only thing I've found so far is an error in the ImageMagik version. Apparently I had a bad file name call in my script. I'm going to try that version again tonight.

too much information

 4:23 am on Aug 10, 2010 (gmt 0)

Alright, I got it working again. The GD Library is the way to go, it is much faster and the resulting thumbs are much smaller than what I was getting with phpthumb.

In the end, turning on my error messages helped me find three errors in the code. One being that I had a bad file name and the others having to do with my database values for another part of the script.

Thanks for the help guys!

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved