1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Getting and setting image resolution

Discussion in 'PHP' started by accessionuk, Jun 25, 2005.

  1. #1
    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.
     
    accessionuk, Jun 25, 2005 IP
  2. jbw

    jbw Peon

    Messages:
    343
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #2
    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/ .
     
    jbw, Jun 25, 2005 IP
  3. rickbkis

    rickbkis Peon

    Messages:
    45
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    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 6, 2005 IP
  4. rickbkis

    rickbkis Peon

    Messages:
    45
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    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
     
    rickbkis, Jul 6, 2005 IP
  5. rossriley

    rossriley Guest

    Messages:
    25
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #5
    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.
     
    rossriley, Jul 14, 2005 IP