patawic Posted November 4, 2009 Share Posted November 4, 2009 http://wutwilluchoose.info/xbox/copy2.php Their both in png format. but for some reason the watermarked image is using a gif palette. Heres the code that im curently using <?php header('content-type: image/png'); $watermark = imagecreatefrompng("http://avatar.xboxlive.com/avatar/I%20patawic%20I/avatar-body.png"); imagesavealpha($watermark, false); imagealphablending($watermark, false); $watermark_width = imagesx($watermark); $watermark_height = imagesy($watermark); $image = imagecreatetruecolor($watermark_width, $watermark_height); $image = imagecreatefrompng("base.png"); $size = getimagesize("base.png"); $dest_x = $size[0] - $watermark_width - 0; $dest_y = $size[1] - $watermark_height - 0; imagecopymerge($image, $watermark, $dest_x, $dest_y, 0, -120, $watermark_width, $watermark_height, 100); imagepng($image); imagedestroy($image); imagedestroy($watermark); ?> Link to comment https://forums.phpfreaks.com/topic/180247-php-gd-using-gif-palette-on-png-image/ Share on other sites More sharing options...
patawic Posted November 4, 2009 Author Share Posted November 4, 2009 Bump i still havent managed to fix the quality Link to comment https://forums.phpfreaks.com/topic/180247-php-gd-using-gif-palette-on-png-image/#findComment-951286 Share on other sites More sharing options...
simshaun Posted November 4, 2009 Share Posted November 4, 2009 Take a look at the first user-comment in the docs. Link to comment https://forums.phpfreaks.com/topic/180247-php-gd-using-gif-palette-on-png-image/#findComment-951295 Share on other sites More sharing options...
patawic Posted November 4, 2009 Author Share Posted November 4, 2009 im new to phpgd so id ont know what those functions do :S Link to comment https://forums.phpfreaks.com/topic/180247-php-gd-using-gif-palette-on-png-image/#findComment-951301 Share on other sites More sharing options...
simshaun Posted November 4, 2009 Share Posted November 4, 2009 You copy this function in to your script and use it in place of imagecopymerge, and hope it works. Link to comment https://forums.phpfreaks.com/topic/180247-php-gd-using-gif-palette-on-png-image/#findComment-951305 Share on other sites More sharing options...
patawic Posted November 4, 2009 Author Share Posted November 4, 2009 it didnt work. but thats probably because ive done it wrong Heres my code <?php header('content-type: image/png'); $watermark = imagecreatefrompng("http://avatar.xboxlive.com/avatar/patawic/avatar-body.png"); $watermark_width = imagesx($watermark); $watermark_height = imagesy($watermark); $image = imagecreatetruecolor($watermark_width, $watermark_height); $image = imagecreatefrompng("base.png"); $size = getimagesize("base.png"); $dest_x = $size[0] - $watermark_width - 0; $dest_y = $size[1] - $watermark_height - 0; imagecopymerge_alpha($image, $watermark, $dest_x, $dest_y, 0, -120, $watermark_width, $watermark_height, 100); imagepng($image); imagedestroy($image); imagedestroy($watermark); function imagecopymerge_alpha($dst_im, $src_im, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h, $pct){ $opacity=$pct; // getting the watermark width $w = imagesx($src_im); // getting the watermark height $h = imagesy($src_im); // creating a cut resource $cut = imagecreatetruecolor($src_w, $src_h); // copying that section of the background to the cut imagecopy($cut, $dst_im, 0, 0, $dst_x, $dst_y, $src_w, $src_h); // inverting the opacity $opacity = 100 - $opacity; // placing the watermark now imagecopy($cut, $src_im, 0, 0, $src_x, $src_y, $src_w, $src_h); imagecopymerge($dst_im, $cut, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h, $opacity); } ?> Link to comment https://forums.phpfreaks.com/topic/180247-php-gd-using-gif-palette-on-png-image/#findComment-951308 Share on other sites More sharing options...
patawic Posted November 4, 2009 Author Share Posted November 4, 2009 using the larger function below. it removes the black area around the character but it still uses a 256 colour palette http://www.wutwilluchoose.info/xbox/copy2.php Link to comment https://forums.phpfreaks.com/topic/180247-php-gd-using-gif-palette-on-png-image/#findComment-951314 Share on other sites More sharing options...
patawic Posted November 4, 2009 Author Share Posted November 4, 2009 Ive managed to remove the black now Its still stuffing up the palette :S Link to comment https://forums.phpfreaks.com/topic/180247-php-gd-using-gif-palette-on-png-image/#findComment-951328 Share on other sites More sharing options...
patawic Posted November 4, 2009 Author Share Posted November 4, 2009 Due to the edit button misteriously disappearing heres my current code <?php header('content-type: image/png'); $watermark = imagecreatefrompng("http://avatar.xboxlive.com/avatar/i%20patawic%20i/avatar-body.png"); $watermark_width = imagesx($watermark); $watermark_height = imagesy($watermark); $image = imagecreatetruecolor($watermark_width, $watermark_height); $image = imagecreatefrompng("base.png"); $size = getimagesize("base.png"); $dest_x = $size[0] - $watermark_width - 0; $dest_y = $size[1] - $watermark_height - 0; imagecopymerge_alpha($image, $watermark, $dest_x, $dest_y, 0, -120, $watermark_width, $watermark_height, 100); imagepng($image); imagedestroy($image); imagedestroy($watermark); function imagecopymerge_alpha($dst_im, $src_im, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h, $pct){ if(!isset($pct)){ return false; } $pct /= 100; // Get image width and height $w = imagesx( $src_im ); $h = imagesy( $src_im ); // Turn alpha blending off imagealphablending( $src_im, false ); // Find the most opaque pixel in the image (the one with the smallest alpha value) $minalpha = 127; for( $x = 0; $x < $w; $x++ ) for( $y = 0; $y < $h; $y++ ){ $alpha = ( imagecolorat( $src_im, $x, $y ) >> 24 ) & 0xFF; if( $alpha < $minalpha ){ $minalpha = $alpha; } } //loop through image pixels and modify alpha for each for( $x = 0; $x < $w; $x++ ){ for( $y = 0; $y < $h; $y++ ){ //get current alpha value (represents the TANSPARENCY!) $colorxy = imagecolorat( $src_im, $x, $y ); $alpha = ( $colorxy >> 24 ) & 0xFF; //calculate new alpha if( $minalpha !== 127 ){ $alpha = 127 + 127 * $pct * ( $alpha - 127 ) / ( 127 - $minalpha ); } else { $alpha += 127 * $pct; } //get the color index with new alpha $alphacolorxy = imagecolorallocatealpha( $src_im, ( $colorxy >> 16 ) & 0xFF, ( $colorxy >> 8 ) & 0xFF, $colorxy & 0xFF, $alpha ); //set pixel with the new color + opacity if( !imagesetpixel( $src_im, $x, $y, $alphacolorxy ) ){ return false; } } } // The image copy imagecopy($dst_im, $src_im, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h); } ?> but its still using a 256 color palette :S Link to comment https://forums.phpfreaks.com/topic/180247-php-gd-using-gif-palette-on-png-image/#findComment-951332 Share on other sites More sharing options...
simshaun Posted November 4, 2009 Share Posted November 4, 2009 Think I got it. <?php header('content-type: image/png'); $insert = imagecreatefrompng("http://avatar.xboxlive.com/avatar/i%20patawic%20i/avatar-body.png"); $insert_width = imagesx($insert); $insert_height = imagesy($insert); $new_image = imagecreatetruecolor($insert_width, $insert_height); imagefill($new_image, 0, 0, imagecolorallocatealpha($new_image, 255, 255, 255, 127)); imagecopy($new_image, $insert, 0, 125, 0, 0, $insert_width, $insert_height); imagealphablending($new_image, false); imagesavealpha($new_image, true); imagepng($new_image); imagedestroy($new_image); imagedestroy($insert); Link to comment https://forums.phpfreaks.com/topic/180247-php-gd-using-gif-palette-on-png-image/#findComment-951353 Share on other sites More sharing options...
patawic Posted November 5, 2009 Author Share Posted November 5, 2009 does that require the imagecopymerge_alpha function? Link to comment https://forums.phpfreaks.com/topic/180247-php-gd-using-gif-palette-on-png-image/#findComment-951518 Share on other sites More sharing options...
simshaun Posted November 5, 2009 Share Posted November 5, 2009 Does it look like it does? (no) Link to comment https://forums.phpfreaks.com/topic/180247-php-gd-using-gif-palette-on-png-image/#findComment-951772 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.