I reproduce the test with the latest CI version from SVN (r1064)
I get the same result as you Derek, but like you can see, it looks bad, the transparency is absolutely not kept and the overlay picture looks not good.
Here is the test result before and after
I run also some test using a watermarker plugin that I already been talked with you some time ago Derek, and the result looks exactly how it is expected to be, here is the result with this plugin:
http://www.webready.fr/uploads/flower_watermarker-plugin.jpg
As you can see, the plugin render is perfect, so maybe you will use the plugin code to solve the bug in CI. I am honest with you: I had a look at CI’s image lib tried to put in the watermarker code to solve the bug but I get no success, so maybe you will just do it better than me.
Here is the code of the plugin:
/applications/plugins/watermarker_pi.php
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
function watermark($sourcefile, $watermarkfile) {
#
# $sourcefile = Filename of the picture to be watermarked.
# $watermarkfile = Filename of the 24-bit PNG watermark file.
#
//Get the resource ids of the pictures
$watermarkfile_id = imagecreatefrompng($watermarkfile);
imageAlphaBlending($watermarkfile_id, false);
imageSaveAlpha($watermarkfile_id, true);
$fileType = strtolower(substr($sourcefile, strlen($sourcefile)-3));
switch($fileType) {
case('gif'):
$sourcefile_id = imagecreatefromgif($sourcefile);
break;
case('png'):
$sourcefile_id = imagecreatefrompng($sourcefile);
break;
default:
$sourcefile_id = imagecreatefromjpeg($sourcefile);
}
//Get the sizes of both pix
$sourcefile_width=imageSX($sourcefile_id);
$sourcefile_height=imageSY($sourcefile_id);
$watermarkfile_width=imageSX($watermarkfile_id);
$watermarkfile_height=imageSY($watermarkfile_id);
$dest_x = $sourcefile_width - $watermarkfile_width;
$dest_y = $sourcefile_height - $watermarkfile_height;
// if a gif, we have to upsample it to a truecolor image
if($fileType == 'gif') {
// create an empty truecolor container
$tempimage = imagecreatetruecolor($sourcefile_width, $sourcefile_height);
// copy the 8-bit gif into the truecolor image
imagecopy($tempimage, $sourcefile_id, 0, 0, 0, 0,
$sourcefile_width, $sourcefile_height);
// copy the source_id int
$sourcefile_id = $tempimage;
}
imagecopy($sourcefile_id, $watermarkfile_id, $dest_x, $dest_y, 0, 0,
$watermarkfile_width, $watermarkfile_height);
//Create a jpeg out of the modified picture
switch($fileType) {
// remember we don't need gif any more, so we use only png or jpeg.
// See the upsaple code immediately above to see how we handle gifs
case('png'):
imagepng ($sourcefile_id, $sourcefile);
break;
default:
imagejpeg ($sourcefile_id, $sourcefile);
}
imagedestroy($sourcefile_id);
imagedestroy($watermarkfile_id);
}
?>
And here is the code used in the Controller to test:
<?php
class Png_test extends Controller {
function Png_test()
{
parent::Controller();
}
function index()
{
$this->load->plugin('watermarker');
$sourcefile = './uploads/flower.jpg';
$watermarkfile = './uploads/png24-watermark.png';
watermark($sourcefile, $watermarkfile);
}
}
?>