Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

resizing images

how to compress images so they look right



12:51 pm on Jun 1, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

I am using the functions
to resize images that have been uploaded. But the images don't look right when they are re-sized.
What functions do you need to use to re-size the image so it looks like it has been re-sized in photoshop?


3:01 pm on Jun 1, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

Generally, the advice I see suggests using imagecopyresampled() for better quality. Choosing an appropriate output file type can also often help, especially if you're using a file type that supports a quality setting like .jpg.

I don't have any real expertise with image manipulation, but I've gotten better results using ImageMagick for these tasks than I did with GD. There are a couple of PHP interfaces like IMagick that make it easy, but my current set-up makes that impractical so I just use system() and passthru() to execute the commands I need. For the simple tasks I have, it works fine. Good luck!


4:13 pm on Jun 1, 2012 (gmt 0)

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member

Agreed on ImageMagick, even if you use it just for simple resizing it is more efficient (see below.) What's required is:

- ImageMagick binaries installed (most 'nix installations already have this)
- PHP must be compiled with iMagick, the PHP interface to ImageMagick. Many installations do not have this by default, you'll have to re-compile it or get your host to do so.

GD performs all it's functions in memory. What this means is if you have a compressed jpg, it will map it out in memory as an UNcompressed bitmap, which can often be huge.

For images larger than 2 MB, which is most raw camera images, you will often get "XX bytes of memory exhausted" using GD. In shared environments, you'll rarely be allowed to up the memory usage near anything useful.

ImageMagick performs most of these actions in virtual memory on disk, conserving memory and is generally faster overall. It also has a lot of things you can't do in GD, and does them better.

Featured Threads

Hot Threads This Week

Hot Threads This Month