Jump to content

Save alpha


doddsey_65

Recommended Posts

Im trying to use a cropping feature but when the image is cropped the alpha channel is lost. Anyone know where im going wrong here?

 

if($ext == 'png')
{
    $srcImg  = imagecreatefrompng('avatars/'.$original);
    $newImg  = imagecreatetruecolor($width, $height);

    imagealphablending($srcImg, true);
    imagesavealpha($srcImg, true);
    imagecopyresampled($newImg, $srcImg, 0, 0, $x1, $y1, $width, $height, $width, $height);
    
    imagepng($newImg, 'avatars/'.$user_name.'_avatar_cropped.png');

    $link->query("UPDATE ".TBL_PREFIX."users
                    SET u_avatar_cropped = '".$user_name."_avatar_cropped.png'
                    WHERE u_username = '$user_name'")
                    or die(print_link_error());
}

Link to comment
https://forums.phpfreaks.com/topic/230514-save-alpha/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.