【问题标题】:PHP displaying JPG image from PNG source on server?PHP在服务器上显示来自PNG源的JPG图像?
【发布时间】:2015-06-16 22:24:20
【问题描述】:

是否可以在我的服务器上有 png 图像,但有一个 php 脚本将它们转换为 jpg(并压缩它们)并在查看时缓存它们?

【问题讨论】:

    标签: php png converter jpeg


    【解决方案1】:

    是的,有可能,您可以使用短语“png 转换为 jpg php

    Use PHP to convert PNG to JPG with compression?

    【讨论】:

      【解决方案2】:

      您可以使用此脚本将 PNG 图像转换为 JPEG 图像。

      $input_file = "test.png";
      $output_file = "test.jpg";
      
      $input = imagecreatefrompng($input_file);
      list($width, $height) = getimagesize($input_file);
      $output = imagecreatetruecolor($width, $height);
      imagecopy($output, $input, 0, 0, 0, 0, $width, $height);
      imagejpeg($output, $output_file);
      

      你可以通过这个@Alexandre Jasmin Answer

      【讨论】:

      • 看来这不会缓存图像,即。每次查看页面时都会重新生成它们(这会是速度问题吗?),我必须在这个脚本中添加什么来缓存?因此,如果 png 与上次生成 jpg 时相比发生了变化,它只会生成新的 jpg。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-04-07
      • 1970-01-01
      • 2012-12-24
      • 1970-01-01
      • 2019-08-08
      • 2014-01-03
      • 2020-10-07
      相关资源
      最近更新 更多