|
||||||||
|
||||||||
How To Create Thumb nails in PHP When you resize a large image it takes ages to load and if you have a page of these images such as search results or a gallery it can be a nightmare for users so the answer is to create thumbnails. Below is a modified script I use to create thumbnails function createthumbnail($name,$filename,$new_w,$new_h,$oldx,$oldy) Now this function will work fine, however due to the processing power required to perform these calculations you will need to up your PHP.ini stats upload_max_filesize = 20M; This is very extreme however it should deal with most images then. There is a problem I have found on images with more than 3000*3000 pixels. It wont accept them and will return an error. Now this is not due to the process time or memory limited needed for this is only just over 8mb ((3000*3000)/(1024*1024)) however with a limit of 512m it should handle it but does not. I believed this was a server problem but after trying on a few servers it will not work. There for I believe it is a restriction on the imagecreatefromjpeg command that cannot handle images of that larger dimension. The solution for now is to put a get out clause in your code and if the dimensions are to big then just rename the image with your thumbnail extension such as function createthumb2($name,$filename,$new_w,$new_h,$oldx,$oldy) if (!copy($file, $newfile)) The alternative is to not allow images of those dimensions to be entered into the system but then the user has to work out how to resize them manually. Also note is does not matter how big the image is in terms of file size it’s the dimensions that count. Hope this helps someone any problems with this Email Me |
||||||||
![]() ![]() |