I'm using a crop & resize function for images, but I need to let it crop/resize ONLY png files WITH transparent backgrounds, at least 1 pixel in the image should be transparent for the image to be accepted.
Is possible to check if a PNG image has transparent background/pixels?
I'm using PHP and GD libraries.
EDIT: Ok, I've figured out how to do this on PHP with GD libraries. Look how clean it looks! :)
<?php
$im = imagecreatefrompng("php.png");
$rgba = imagecolorat($im,1,1);
$alpha = ($rgba & 0x7F000000) >> 24;
var_dump($alpha);
?>
Any ideas how to do an array for the x/y coordenates to check all the image pixels looking for at least 1 pixel = $alpha = 127?
You can call out to imagemagick for it:
https://www.imagemagick.org/discourse-server/viewtopic.php?t=18596
convert my_image.png -format "%[opaque]" info:
False
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With