使用 php 和 GD 打印高质量图像

发布于 2024-10-27 04:53:06 字数 173 浏览 1 评论 0原文

我需要拍摄某人通过表单上传的照片,调整大小,与高分辨率框架 @ 300dpi 合并,并保持全部 @ 300dpi 以获得最佳打印质量。

是否可以通过 GD 处理高分辨率图像,如果可以,您能否提供一些有关如何处理的信息?我有代码已经可以调整大小和合并,但我不确定它是否能在正确的 dpi 下工作。

谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

有深☉意 2024-11-03 04:53:06

这基本上是可能的:只需使用适量的像素即可。 (dpi 单位在数字成像中没有任何意义,它仅用于将数字[像素]图像转换为物理格式)。

示例:

11 x 8 inch canvas @300 dpi = 3300 x 2400 pixels 

但是,您需要足够的内存来处理这么大的图像。经验法则是,

needed bytes = width x height x 3 (or 4 if alpha-channels are used)

如果您进行复制或调整大小,则此要求会增加,因为脚本需要在内存中保留多个副本。

您需要一个非常慷慨的 memory_limit 设置才能使其发挥作用。

另请注意,GD 只能处理 RGB 图像。

对于大图像和 CMYK 数据,如果您可以在服务器上使用 ImageMagick 可能是更好的选择。

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.

心如狂蝶 2024-11-03 04:53:06

DPI 是用于打印目的的转换系数。这与 GD 如何看待图像完全没有关系。 200 像素 x 150 像素的图像始终是 200 像素 x 150 像素,无论是 10dpi 还是 5000dpi。

但是,当您打印图像时,200x150 @ 10dpi 将生成 20 英寸 x 15 英寸(300 平方英寸)的图像,而 5000dpi 版本将生成 0.04x0.03(0.0012 平方英寸)。

唯一的限制是您必须有足够的内存供 PHP 保存内存中的已解码图像内容。 24 位 1000x1000 像素图像至少需要 1000x1000x3 = 大约 3meg 字节的内存(加上内部开销)。然后额外的内存来保存新图像,其中将包含图像处理的结果。

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.

像极了他 2024-11-03 04:53:06

网页上的默认图像 dpi 为 72 或 96(Mac 或 Windows/Linux)。您可以使用 img 标签的宽度和高度属性指定图像的宽度和高度,并生成具有所需 dpi 的图像。

<img src="/images/image.png" width="300" height="200">

假设您的默认屏幕分辨率是 72,那么创建一个 $resdpi 变量:

$resdpi = $resolution / 72;

然后,将 GD 上的图像的宽度和高度乘以该变量,您将得到一个显示的大图像就像屏幕上默认的 72dpi 一样,但打印时的分辨率要高得多。

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.

坏尐絯 2024-11-03 04:53:06

GD 与像素有关,DPI 不参与其中,因为这需要某种设备输出。如果您知道最终的打印尺寸,则只需确保以像素为单位的尺寸在您需要的 DPI 下正确缩放即可。

一般来说,如果您使用大图像,您的主要问题将是速度和内存使用方面的效率。我建议使用 ImageMagick 来完成更复杂的工作。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文