Internet Advertising - Find jobs - Turquoise Rings - ID card - Web Hosting

PDA

View Full Version : Getting and setting image resolution


accessionuk
Jun 25th 2005, 3:45 pm
Does anyone know how to get and set the resolution of an image using php? For example I need to be able to convert a 72dpi image to 300dpi, while keeping the absolute pixel size of the image the same. Thankyou.

jbw
Jun 25th 2005, 5:25 pm
Iterpulation going from smaller resolutions to fake larger ones can look pretty bad, especially with bad alogrithms, and you are not going from 75 to 300 here , so it is not a simple multiple. Out of the free software for this, I would try ImageMagik, for php you would use http://www.magickwand.org/download/php/ .

rickbkis
Jul 6th 2005, 11:30 pm
Nothing canned. GD is about the closest you can get, but the only thing it retrieves from the image headers is the size and the IPTC information.

Seems like there used to be functions to extract and reset JPEG markers, but I can't find anything in the current docs, so maybe they took it out.

I resorted to writing a bunch of C++ code to do this sort of thing. It could be ported to PHP, I suppose. If you're only hitting one marker, it shouldn't be too much of a performance hit (although you do have to read in and write out the entire file to do it.)

Also: Changing the resolution without changing the pixels dimension changes the size on the output device (except screen), yes?

rickb

rickbkis
Jul 6th 2005, 11:38 pm
Good point about ImageMagic - it can retrieve and rewrite header information. If there's a PHP interface for that, it might be helpful.

FWIW: Resolution is just a number stuck in the header that tells what DPI the output should be. Unchanged pixel dimensions (which is what you're looking for) but changed resolution will result in different size on the output device (assuming it honors the resolution number. Web browsers don't, for instance - printers do.)

rickb

rossriley
Jul 14th 2005, 3:00 pm
Imagemagick can do this. Off the top of my head the command is...
mogrify -density 300 filename.jpg
Within php you can put that inside a system() command.