关于图像文件的问题
我正在编写一个 PHP 脚本来将图像文件上传到服务器,但我有几个问题?
有没有办法减少图像的大小(以千字节为单位)?
当我使用这些文件时,将这些图像嵌入页面的最佳做法是什么?我的意思是我总是需要下载整个页面吗?
最后,当调整页面大小(例如250X250像素)时,为了不面临分辨率问题,有哪些做法?
我希望我的问题不是太笼统。提前致谢!
I am writing an PHP script to upload image files to the server and I have a few questions?
Is there a way to decrease the size of images in terms of kilobytes?
When I am using those files what is the best practice to embed those images into page? I mean do I always have to download the whole page?
Lastly, When resizing the pages(like 250X250 pixels) what is the pratice in order not to face the resolution problems?
I hope my questions are not too general. Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您正在讨论在上传之前减小图像的大小,则 PHP 则无法做到这一点,除非您在发送文件之前使用 HTML5/Flash 之类的工具对文件进行预处理。
您想要做什么,在用户上传该图像后,验证该文件是否是真实图像,然后使用某个库(如果您使用框架,它可能有一种调整图像大小的方法)将图像大小调整为任何最大宽度或您想要的最大高度或最大宽度和高度。
这将减小图像的大小。
对于第二个问题,如果我理解的话,你正在谈论当用户上传 500x500 并且你希望它是 400x250 时,那么你必须缩放和裁剪,这样图像就不会被拉伸,而是从图像中拉伸几个像素。顶部或底部可能会被移除。
If you are talking about decreasing the size of the image before is uploaded, you can't with PHP, unless you use something like HTML5/Flash to pre-process the file before being sent.
What you want to do, after a user uploads that image, verify that the file is a real image, then using some library (if you use a framework, it probably has a way to resize images) resize the image to whatever max width or max height or max width and height you are wanting.
This will decrease the size of an image.
For the 2nd question, if I understand it, you are talking about what about when a user uploads a 500x500 and you want it to be 400x250, then you must scale and crop, this way the image is never stretched but a few pixels from the top or the bottom will probably be removed.
看看这个 http://www.webmotionuk.co .uk/php-jquery-image-upload-and-crop/ - 还有许多其他免费工具可以在上传后转换图像。分辨率不应该是一个问题,当您为 html 中的图像对象指定一个巨大且不成比例的尺寸时,通常会出现问题。
这是另一个 php resizer 我有之前使用过此代码来执行您所要求的操作。
Take a look at this http://www.webmotionuk.co.uk/php-jquery-image-upload-and-crop/ - There are many other free tools out there to convert images after the upload. The resolution shouldn't be an issue that is usually a problem when you give a size to an image object in html that is huge and not proportioned.
Here is another php resizer I have used this code before to do what you are requesting.
您需要根据收到的图像创建一张新图像。
您应该首先看一下 PHP GD 函数。
例如:http://ch2.php.net/manual/en/function。 imagecreatefromjpeg.php
你所说的嵌入是什么意思?
You'll need to create a new image, based on the one you received.
You should first take a look at the PHP GD functions.
For instance: http://ch2.php.net/manual/en/function.imagecreatefromjpeg.php
What do you mean by embedding?