Reputation: 4767
I need to take a photo someone has uploaded through a form, resize, merge with a high-res frame @ 300dpi and keep it all @ 300dpi for the best quality for print.
is it possible to handle high-res images through GD and if so, could you provide some information on how? I have code that already does the resizing and merging, but i'm not sure if its going to work at the correct dpi.
Thanks
Upvotes: 3
Views: 4203
Reputation: 11
The default image dpi on a web page is 72 or 96 ( Mac or Windows/Linux ). You can specify the width and heigth of a image using the width and height attibutes of the img tag and generate the image with the desired dpi within.
<img src="/images/image.png" width="300" height="200">
Let's say that your default screen resolution is 72, than make a $resdpi
variable:
$resdpi = $resolution / 72;
then, make the image on GD multiplying the width and height by that variable and you'll get a large image that will appear like a default 72dpi on screen, but will print with much more resolution.
Upvotes: 1
Reputation: 20602
GD is all about pixels, DPI does not come in to it, as that requires some sort of device output. If you know your final print size, then just ensure that the dimensions in pixels scale correctly at the DPI you require.
Generally, if you are using large images, your main problem is going to be efficiency, both in speed and memory usage. I would recommend using ImageMagick for more complicated jobs.
Upvotes: 0
Reputation: 360602
DPI is a conversion factor for print purposes. It has absolutely no bearing on how GD will see the image. An image that is 200 pixels by 150 pixels will always be 200 pixels by 150 pixels, whether it's 10dpi or 5000dpi.
however, when you print out the image, 200x150 @ 10dpi would make for 20 inch by 15 inch image (300 square inches), while the 5000dpi version would make for 0.04x0.03 (0.0012 square inches).
The only limitation is that you have to have enough memory available for PHP to hold the DECODED image contents in memory. a 24bit 1000x1000 pixel image requires 1000x1000x3 = roughly 3meg bytes of memory, at mininum (plus internal overhead). Then extra memory to hold the new images which will have the results of your image manipulations.
Upvotes: 1
Reputation: 449395
It's basically possible: Just use the proper amount of pixels. (The dpi
unit has no meaning in digital imaging, it serves only to convert a digital [pixel] image into a physical format).
Example:
11 x 8 inch canvas @300 dpi = 3300 x 2400 pixels
However, you'll need plenty of memory to deal with images this large. The rule of thumb is
needed bytes = width x height x 3 (or 4 if alpha-channels are used)
this requirement increases if you do copying or resizing, because the script needs to keep multiple copies in memory.
You will need a very generous memory_limit
setting for this to work.
Also note that GD can only deal with RGB images.
For large images and CMYK data, ImageMagick may be a better option if you can use it on your server.
Upvotes: 7