I’ve a code that unzip files that I upload to my server, it works without any problem.
But now I want to add another function. I want to convert all images that are in .zip file (.zip file only contains images) from .jpg format to .bmp.
<?php $file = $target_path1; $path = $target_path2; $zip = new ZipArchive; $res = $zip->open($file); if ($res === TRUE) { $zip->extractTo($path); $zip->close(); unlink($target_path1); } ?>
There is some easy way to do it? If there is not, at least could I get name of extracted images?
Thanks.
Advertisement
Answer
You first create an image object out of your file with imagecreatefromjpeg(). You then dump that object into different formats (using imagegif() for example):
$imageObject = imagecreatefromjpeg($imageFile); imagegif($imageObject, $imageFile . '.gif'); imagepng($imageObject, $imageFile . '.png'); imagewbmp($imageObject, $imageFile . '.bmp');