I have a transparent png image that I would like to make a copy of then crop to a 1×1 transparent image.
I’m stuck on the “crop to a 1×1 transparent image” part.
I can either modify the existing image or create new image and overwrite the existing one. I believe both options would work. I’m just not sure how to do either and end up with a 1×1 pixel transparent png image.
Any help much appreciated.
function convertImage(){
$file1 = "../myfolder/image.png";
$file2 = "../myfolder/image-previous.png";
if (!file_exists($file2))
{
//make a copy of image.png and name the resulting file image-previous.png
imagecopy($file2, $file1);
// convert image.png to a 1x1 pixel transparent png
// OR
// create a new 1x1 transparent png and overwrite image.png with it
???
}
}
Make use of the
imagecopyresizedmethod that PHP has for you.More information about imagecopyresized
Example: