如何使用PHP调整高分辨率图片的大小 [英] How do You Resize a High Resolution Picture with PHP

查看:274
本文介绍了如何使用PHP调整高分辨率图片的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户上传照片时,我正在处理图像,但我的问题是很高的照片。如何检测用户上传的时间?我正在使用GD库的PHP。使用imagejpeg()方法将质量设置为90不会对其执行任何操作,但会缩放尺寸,然后将ppi设置为72.我希望能够保留尺寸并同时将ppi降至72。任何建议都将不胜感激。

I'm processing images when the user uploads a pic but my problem is high rez pics. How do you detect when the user uploads one? I'm using the GD library for PHP. Setting the quality to 90 with the imagejpeg() method doesn't do anything to it but scales the dimension and then sets the ppi to 72. I want to be able to preserve the dimension and drop the ppi to 72 at the same time. Any advice would be greatly appreciated.

推荐答案

就你需要关注的而言,没有PPI这样的东西。此外,DPI不存在于数字中。只有像素和尺寸(这只是两个方向上像素的度量)。

There is no such thing as PPI as far as you need to be concerned. Also, DPI doesn't exist in digital. There are only pixels, and the dimensions (which are just a measurement of pixels in either direction).

你真正要做的是对图像进行下采样,减少图像的整体尺寸。您可能希望按比例执行此操作,也就是说您希望保持相同的宽高比,以便在重新采样后图像不会显示为拉伸。另外值得注意的是,调整大小和重新采样的不同之处在于,调整大小并不会过多地关注内容,从而导致视觉上很差的调整大小的图像。您可能想要重新采样。

What you are really trying to do is downsample an image, reducing the overall dimensions of an image. You will probably want to do it proportionally, which is to say you want to keep the same ratio of width to height so that the image doesn't appear stretched after resampling it. Also worth noting, resizing and resampling differ in that resizing doesn't pay much attention to the content, resulting in very visually-poor resized images. You probably want resampling.

PHP文档中有一些很好的示例处理上传的文件以及如何使用GDImage库调整图像大小。我建议你看看。您可能想了解的其他相关方法:

The PHP documentation has some great examples on handling uploaded files as well as how to resize images using the GDImage library. I suggest you check them out. Other relevant methods you might want to know about:

  • getimagesize() will let you check the dimensions of an image without opening it (useful to check if it needs to be resized without loading it up).
  • imagesx() and imagesy() grab dimensions of a GD Image resource.

这篇关于如何使用PHP调整高分辨率图片的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆