Compress jpeg on server with PHP

前端 未结 4 567
天涯浪人
天涯浪人 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条回答
  •  时光说笑
    2020-12-06 18:05

    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
    

提交回复
热议问题