Show one image in different qualities using PHP
Is there a way to show one image in different qualities on fly? ie:
<img src=show_img.php?img_src=http://www.simpsoncrazy.com/content/pictures/homer/HomerSimpson3.gif&img_quality=25>
<img src=show开发者_JAVA技巧_img.php?img_src=http://www.simpsoncrazy.com/content/pictures/homer/HomerSimpson3.gif&img_quality=50>
<img src=show_img.php?img_src=http://www.simpsoncrazy.com/content/pictures/homer/HomerSimpson3.gif&img_quality=75>
First, you can use a tool like Imagick to do the compression, resizing, etc.
Second, while you have the right idea in pointing your img src to a PHP script, consider the security implications of allowing a full URL as a parameter in the request. What if someone uses your code to point to an image on a different website with copyrighted material? Don't leave yourself exposed as an open proxy...
The gif format doesn't have the ability to be output with different quality settings. When you output a gif using GD, it automatically uses the GIF87a format, which supports up to 8 bits per pixel, unless you use imagecolortransparent, which will then set the format to GIF89a.
However, .jpg does and can be set in the 3rd (optional) parameter of imagejpeg (see how to load a .gif from a URL here)
精彩评论