Compress jpeg on server with PHP

前端 未结 4 568
天涯浪人
天涯浪人 2020-12-06 17:45

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 compres

4条回答
  •  猫巷女王i
    2020-12-06 18:02

    The solution provided by vlzvl works well. However, using this solution, you can also overwrite an image by changing the order of the code.

        $image = imagecreatefromjpeg("image.jpg");  
        unlink("image.jpg");
       imagejpeg($image,"image.jpg",50);
    

    This allows you to compress a pre-existing image and store it in the same location with the same filename.

提交回复
热议问题