【发布时间】:2013-05-18 15:37:12
【问题描述】:
几个月前,我编写了以下脚本,用PHP to Retina 和non 视网膜图像转换上传的图像。使用此脚本的 iphone 应用程序仅使用 PNG 图像,因此我编写了使用 PNG 的脚本。
$filename = dirname(__FILE__)."/uploads/" . $_FILES['myFile']['name'];
$filename = str_replace('.png', '_retina.png', $filename);
file_put_contents($filename, file_get_contents($_FILES['myFile']['tmp_name']));
$image_info = getimagesize($filename);
$image = imagecreatefrompng($filename);
$width = imagesx($image);
$height = imagesy($image);
$new_width = $width/2.0;
$new_height = $height/2.0;
$new_image = imagecreatetruecolor($new_width, $new_height);
imagealphablending($new_image, false);
imagesavealpha($new_image, true);
$color = imagecolortransparent($new_image, imagecolorallocatealpha($new_image, 0, 0, 0, 127));
imagefill($new_image, 0, 0, $color);
imagecopyresampled($new_image, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
$new_filename = str_replace('_retina.png', '.png', $filename);
imagepng($new_image, $new_filename);
现在我需要相同的脚本,然后用于 Jpeg 图像。因为 iphone 应用程序会加载分辨率更高的图像,所以我们选择了 Jpeg。但我不知道如何让它发挥作用。
到目前为止我所尝试的:
- 用 jpeg 版本替换
imagecreatefrompng - 用 jpeg 版本替换
imagepng
有没有人有一个有效的例子或有用的链接可以让我找到正确的方向?
【问题讨论】:
-
如果没有透明度,我会使用
imagejpeg。 -
@MaximKhan-Magomedov 啊,等等,它是一个 Jpeg,而我正在使用透明命令,这就是失败的原因吗?
-
我认为如果你从 png 中创建它,你仍然可以使用透明度。当你最后调用 imagejpeg 来保存它时,它会变灰(我认为)。
-
图片还是以 png 格式输入还是以 jpg 格式输入?
-
@Pitchinnate 没有上传为 JPG。