Estuve teniendo problemas para hacer un crop de una imagen transparente (PNG o GIF) en CodeIgniter, encontré un par de lineas de código que me sirvieron y las incluí en la librería de codeIgniter Image_Lib.
Acá les dejo el código modificado para que puedan hacer un resize o un crop de una imagen png o gif conservando las transparencias y alpha.
//Obtenemos la extension
$ext = end(explode(".",$this->full_dst_path));
if($ext == "png" || $ext == "gif"){
$trnprt_indx = imagecolortransparent($src_img);
// If we have a specific transparent color
if ($trnprt_indx >= 0) {
// Get the original image's transparent color's RGB values
$trnprt_color = imagecolorsforindex($src_img, $trnprt_indx);
// Allocate the same color in the new image resource
$trnprt_indx = imagecolorallocate($dst_img, $trnprt_color['red'], $trnprt_color['green'], $trnprt_color['blue']);
// Completely fill the background of the new image with allocated color.
imagefill($dst_img, 0, 0, $trnprt_indx);
// Set the background color for new image to transparent
imagecolortransparent($dst_img, $trnprt_indx);
}
// Always make a transparent background color for PNGs that don't have one allocated already
elseif ($ext == "png") {
// Turn off transparency blending (temporarily)
imagealphablending($dst_img, false);
// Create a new transparent color for image
$color = imagecolorallocatealpha($dst_img, 0, 0, 0, 127);
// Completely fill the background of the new image with allocated color.
imagefill($dst_img, 0, 0, $color);
// Restore transparency blending
imagesavealpha($dst_img, true);
}
}
Aca les dejo un link con la libreria modificada.
Image_lib.rar
Cualquier comentario será bienvenido.



Muchas Gracias, me sirvió perfecto.
Me sorprende que sea el primero en dejar un comentario.
Gran aportación. Con ella solucioné el problema de cortado de pngs con transparencia al paso.
Gracias por compartirlo.
Fran
De nada, si ustedes tienen codigos para aportar seran bienvenidos.
Saludos.