Kevin <ke***@nrgmedia.no> wrote:
Is there anyway to find out an image's DPI using GD?
Can I change an image which is 300 DPI down to 200 DPI?
I am fully aware of that DPI doesn't matter on screen, but these are
to be used for printing, not web :)
hi kevin !
first : sorry for my (very) bad english, but i'm french (and nobody's
perfect...)
well. i speak about jpeg files only.
a jpeg file has structure as following (ie) :
2 first bytes : FF D8 => SOI 'Start Of Image' marker
then (2 bytes) : FF E0 => App0 marker
then (2 bytes) : 00 10 => marker length (the next 14 + these , so 16)
then (5 bytes) : 4A 46 49 46 00 => identifier (JFIF0)
then (2 bytes) : 01 01 => version (1.01)
then (1 byte) : 01 => units for the X and Y densities (00 : no units,
X and Y specify the pixel aspect ratio ;
01 : X and Y are dots per inch ;
02 : X and Y are dots per cm)
then (2 bytes) : 01 2C => horizontal pixel density (01 2C = 300dpi ;
00 01 = 72dpi)
then (2 bytes) : 01 2C => vertical pixel density (01 2C = 300dpi ;
00 01 = 72dpi)
then (1 byte) : 00 => thumbnail horizontal pixel count X
then (1 byte) : 00 => thumbnail vertical pixel count Y
others : ......
since (2 bytes): FF DB => DTQ marker
end others : ......
00 43 00 01 01 01 01 01 01 01 01 01 ...etc
so you can know, reading (with php) the first bytes of a jpeg file (and
especially 14 to 18) the dpi (or dpc) of an image.
now, i speak about picture.
picture is defined by X pixels x Y pixels (ie : 1200px x 856px).
on web (screen) this picture will fill a surface of 1200 pixels by 856
pixels.
but for printing it (on paper) you must calculate :
if you print at 300dpi (good offset), dimensions of your picture on
paper will be 1200/300 by 856/300 so 4 inches by 2.8 inches ;
if you print at 135dpi (offset), dimensions of your picture on paper
will be 1200/3135 by 856/135 so 8.9 inches by 6.3 inches.
and if you want a 12 inches by 8.6 inches picture on paper its
resolution will be 100dpi.
so, you could know the quality of your final print just by know the
dimensions (in pixels) of your jpeg file.
now, i speak about gd.
when i create a jpeg image with gd, i always have a 72dpi image. so i do
not have to read the first bytes of the file, i just use the php
getimagesize function and i calculate :
round((getimagesize($my_picture)[0] * 0.85) / 100)
for width (cm) at 300dpi ;
round((getimagesize($my_picture)[1] * 0.85) / 100)
for height (cm) at 300dpi.
'et voila !'
--
@@@@@
E -00 yes ! france... near japan !
' `) /
|\_ =="