imagejpeg(): 6 is not a valid Image resource in ........ on line 57
Código PHP:
function MascaraImg( $picture, $mask ) {
$xSize = imagesx( $picture );
$ySize = imagesy( $picture );
$newPicture = imagecreatetruecolor( $xSize, $ySize );
imagesavealpha( $newPicture, true );
imagefill( $newPicture, 0, 0, imagecolorallocatealpha( $newPicture, 0, 0, 0, 127 ) );
if( $xSize != imagesx( $mask ) || $ySize != imagesy( $mask ) ) {
$tempPic = imagecreatetruecolor( $xSize, $ySize );
imagecopyresampled( $tempPic, $mask, 0, 0, 0, 0, $xSize, $ySize, imagesx( $mask ), imagesy( $mask ) );
imagedestroy( $mask );
$mask = $tempPic;
}
for( $x = 0; $x < $xSize; $x++ ) {
for( $y = 0; $y < $ySize; $y++ ) {
$alpha = imagecolorsforindex( $mask, imagecolorat( $mask, $x, $y ) );
$alpha = $alpha['alpha'];
$color = imagecolorsforindex( $picture, imagecolorat( $picture, $x, $y ) );
if ($color['alpha'] > $alpha)
$alpha = $color['alpha'];
if ($alpha == 127) {
$color['red'] = 0;
$color['blue'] = 0;
$color['green'] = 0;
}
imagesetpixel( $newPicture, $x, $y, imagecolorallocatealpha( $newPicture, $color[ 'red' ], $color[ 'green' ], $color[ 'blue' ], $alpha ) );
}
}
imagedestroy( $picture );
$picture = $newPicture;
}
if($user !="no"):
$source = imagecreatefromjpeg( $user );
$mask = imagecreatefrompng( 'mascara.png' );
MascaraImg( $source, $mask );
header( "Content-type: image/jpeg");
imagepng( $source ); // linea 57
else:
echo $user;
endif;
alguien que me de algunas ideas?
gracias.