I'm sure this can be easily done but I haven't really worked with GD in the past much so i'm not entirely sure. Anyway, i'm curious about thumbnail creation. What I want is a square thumbnail to be created instead of one taking the same proportions of the full size image. Basically for example an image of 800x600 is used, instead of a thumbnail of 200x150 created I would like one of a size such as 100x100 instead. Anyone have any ideas?
I suggest going the Imagemagick 'convert' way, it's a lot better (at least, for me) - you just need to install Imagemagick and call it from within your PHP script: shell_exec("convert original_file.jpeg -thumbnail 100 thumbnail.jpeg"); PHP: http://www.imagemagick.org HTH, cheers!
I use GD library function for the same .... refer to php manual ... and if you are looking for a ready made class you can find it here http://www.phpclasses.org/browse/package/1370.html
Thanks for the link, but the problem is i'm on a shared server and I don't have access to it. I have been referring to the manual and i'm not really looking for a ready made class. Alot of the tutorials and classes I have found and read don't seem to cater for what I want with the miniture image of 100x100.
http://phpthumb.sourceforge.net/ I know you are not looking for a class, but maybe you can have a look at their source and see if it can help you... Also, I think the example of imagecopyresampled should be interesting for you: http://php.net/manual/en/function.imagecopyresampled.php Cheers
I discovered that just before you post, but thanks anyway. I've put it in a little class file I have created and now i'm wondering of a more efficient way of creating the small 100x100px image. At the moment I shrink the image to a size where the smallest dimension is shrunk to 100px whilst the largest is kept in proportion with that. From that the 100x100px image is created where it a section from the exact center is taken and used. The problem with that method is an image is unnecessarily created wasting resources for nothing. Maybe i'm a little blind or something, but does anyone have an ideas of how it can be done without creating 2 images, instead just a single image?
Uhm... I think you can play with the dst_x, int dst_y, int src_x, int src_y, int dst_w, int dst_h, int src_w, int src_h params of the http://php.net/manual/en/function.imagecopyresampled.php function Sorry I don't have time to look at it now...
Use this: http://www.phptricks.com/lesson.php?id=14 It is very easy to change, just make sure that $newwidth and $newheight are what you want. Peace,
That's what i've been using. I create a smaller version of the image, and then create a small 100x100 section from that. But 2 images are being created by php when I should really only be creating 1. I'm pretty much just curious for basically... the user gives an image of 400x200 and that is shrunk down to 200x100px (smallest dimension is shrunk down to 100px) and then a section of 100x100px is taken from that, so starting 50px from the top and 0px from the left. Thats what I want, but using less resources that what I currently use. Thats because if I do it that way it won't be too good for the server when my site goes live and there are tens, maybe hundreds uploading upto 10 images at a time to have to all processed by the server 2 times each.