使用PHP在服务器上压缩jpeg [英] Compress jpeg on server with PHP

查看:80
本文介绍了使用PHP在服务器上压缩jpeg的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个约有1500张JPEG图像的站点,我想将它们全部压缩.遍历目录不是问题,但是我似乎找不到用于压缩服务器上已经存在的JPEG的函数(我不想上传新的JPEG)并替换旧的函数.

I have a site with about 1500 JPEG images, and I want to compress them all. Going through the directories is not a problem, but I cannot seem to find a function that compresses a JPEG that is already on the server (I don't want to upload a new one), and replaces the old one.

PHP是否为此提供了内置功能?如果没有,如何从文件夹中读取JPEG到脚本中?

Does PHP have a built in function for this? If not, how do I read the JPEG from the folder into the script?

谢谢.

推荐答案

您没有告诉您是否正在使用GD,所以我认为是这样.

you're not telling if you're using GD, so i assume this.

$img = imagecreatefromjpeg("myimage.jpg");   // load the image-to-be-saved

// 50 is quality; change from 0 (worst quality,smaller file) - 100 (best quality)
imagejpeg($img,"myimage_new.jpg",50);

unlink("myimage.jpg");   // remove the old image

这篇关于使用PHP在服务器上压缩jpeg的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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