I am using the functions imagecreatetruecolor imagecopyresized 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?
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!
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.