print quality images with php and GD

微笑、不失礼 提交于 2019-12-06 01:15:14

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.

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.

Humberto Cruz

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!