imagepng imagecreatefrompng php png transparency

php - imagepng - imagecreatefrompng



Transparencia PNG con PHP (5)

Olvídese del índice de transparencia de color, nunca funciona en todos los productos de representación. En su lugar, use una máscara de capa alfa:

$image = imagecreatetruecolor($size, $size); imagealphablending($image, false); imagesavealpha($image, true); $trans_layer_overlay = imagecolorallocatealpha($image, 220, 220, 220, 127); imagefill($image, 0, 0, $trans_layer_overlay);

Oye, tengo problemas para tratar de mantener la transparencia en una png cuando creo una miniatura de ella, ¿alguien alguna experiencia con esto? cualquier ayuda sería genial, esto es lo que estoy haciendo actualmente:

$fileName= "../js/ajaxupload/tees/".$fileName; list($width, $height) = getimagesize($fileName); $newwidth = 257; $newheight = 197; $thumb = imagecreatetruecolor($newwidth, $newheight); imagealphablending($thumb, true); $source = imagecreatefrompng($fileName); imagealphablending($source, true); imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); imagesavealpha($thumb, true); imagepng($thumb,$newFilename);



Esas funciones acceden a la biblioteca gdlib subyacente, que es un buen juguete, pero no es algo que produce buenos resultados. Si tiene la opción, use imagemagick en su lugar. La desventaja es que actualmente no hay buenas conexiones de php, por lo que debe acceder a ellas a través del intérprete de comandos, que normalmente no está permitido en los hosts compartidos.


He tenido éxito haciéndolo así en el pasado:

$thumb = imagecreatetruecolor($newwidth, $newheight); imagealphablending($thumb, false); imagesavealpha($thumb, true); $source = imagecreatefrompng($fileName); imagealphablending($source, true); imagecopyresampled($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); imagepng($thumb,$newFilename);

Encontré la calidad de imagen de salida mucho mejor usando imagecopyresampled() que imagecopyresized()