This question appears here once every two weeks. And every time somebody advises to resize images with ImageCopyResampled() which requries a lot of work and later the script start failing with "out of memory" error, because some idiot uploads his 7Mpx photo to make a 80x80 avatar. Use command-line ImageMagick utility called "convert" instead:
PHP Code:
exec("convert {$infile} -scale '80x80>' {$outfile}");
Advantages:
- no need to find out the format (jpg, gif, png or whatever) of the input file
- no need to manually set the format of the output file (both are set by utility according to file extension)
- no need to calculate ratio and dimensions of the output file
- no limit on the input file filesize and resolution
- works ten times faster than the script
Disadvantages:
- can only be run through exec() or similar functions which most web developers are afraid of for some unknown reason.
|