

$phpThumb->GenerateThumbnail() // Generate the thumbnail $phpThumb->setParameter('q', 100) // Specify quality $phpThumb->setParameter('zc', 1) // Specify zoom-crop (instead of stretch)

$phpThumb->setParameter('h', $height) // Set height $phpThumb->setParameter('w', $width) // Set width $phpThumb->setSourceData(file_get_contents($_GET)) Load data into phpThumb object and set parameters
PHP MEMORY LIMIT WORDPRESS IMAGE RESIZE 1AND1 CODE
After adding two PHP files to my web directory ( and ) I was able to use the following code to generate my thumbnails: include("") I had spent some time trying to debug PHP code that used GD directly, but failed on large images and on a subset of images that seemed to have minor errors that choked GD.īut then I found phpThumb ( ), and I'm never going back. That will gives you the path of the binary, if exists. To know if convert is available on your server, you can try this (in PHP) : $out = array() Putenv('MAGICK_THREAD_LIMIT=1') // limit the number of thread for the binary. Set_time_limit(0) // ignore server timeout I also needed to put some other lines in my PHP to avoid some collateral issues : ignore_user_abort(true) // ignore user abort : let the script finish resizing even if user aborts I suggest you to divide this value by 2 or 4 to be confortable). You will probably need to fit the values to match the values of your server (Generally PHP tells you the maximum allocated memory when it gives you the Fatal Error. This is the way you limit the memory used by the binary (here : 32Mo).

The real deal is about -limit memory 32 and -limit map 32. Nice -5 is also a unix command to change the priority of a processĬonvert. exec('env MAGICK_TMPDIR= nice -5 convert -limit memory 32 -limit map 32 -resize 800圆00 huge.jpg reasonable.jpg') Įnv MAGICK_TMPDIR= set up a temp directory for imagemagick It needs imagemagick, but I discovered that most of the providers natively provides this on their servers, even shared ones. Moreover, providers memory limit differs from one to another.Īnd change the memory_limitin PHP does not work on shared servers, providers usually limit the ram even if phpinfo() says that you got 128Mo (1and1 limits RAM to 60Mo per process for example).īut I finally found something quite efficient here : I got stuck for days (and nights) with this problem.
