PHP:我怎么可以转换JPEG至PNG,然后压缩(不进行复制)

问题描述:

那么我现在要做的是: - 给定一个图像URL - >图像转换成PNG - 拉链导致PNGPHP:我怎么可以转换JPEG至PNG,然后压缩(不进行复制)

我有下面的代码,成功地执行转换和压缩和解(我打算以后将它扩大到测试扩展到自动转换格式):

$file = "../assets/test.jpg"; 
$img = imagecreatefromjpeg($file); 
imagePng($img, "files/temp.png"); 
$zip->addFile("files/temp.png", "test.png"); 

我想知道的是,是否有可能在压缩之前不需要创建图像的副本

ZipArchive::addFromString()

$file = "../assets/test.jpg"; 

// capture output into the internal buffer 
ob_start(); 

$img = imagecreatefromjpeg($file); 
imagepng($img); 

// get contents from the buffer 
$contents = ob_get_clean(); 

$zip = new ZipArchive(); 
$zip->open('archive.zip', ZipArchive::CREATE); 

// and put them in the zip file... 
$zip->addFromString('name_in_the_zip.png', $contents); 
+0

谢谢你的工作:) – iakiak