I have been tasked with overlaying a photo on to a newspaper-esque image where the photo is of a person and they are meant to be the photo on the front of a newspaper.
I used codeigniter image library to watermark the template with the photo. It works fine but it distorts or removes some of the pixels in the photo when its overlayed
You can see it in the top left of the photo here-
I am also resizing the image up as its 500 px and the space for the image in the template is around 1400px
Here is the code i am using to overlay the image
private function overlay($template, $source_image)
{
echo $template;
// $config = array();
$config['source_image'] = $template;
$config['image_library'] = 'gd2';
$config['wm_type'] = 'overlay';
$config['wm_overlay_path'] = $source_image;
$config['wm_vrt_alignment'] = 'top';
$config['wm_hor_alignment'] = 'left';
$config['wm_hor_offset'] = '18px';
$config['wm_vrt_offset'] = '843px';
$config['quality'] = '100%';
$this->image_lib->initialize($config);
$result = $this->image_lib->watermark();
if($result){
return $result;
}
else
{
echo $this->image_lib->display_errors();
return false;
}
}
Since there was no answer i ended up using native php functions which worked.
imgpng has a 2nd parameter if you wish to saved the file to your server instead. Since they were being printed on a click of the button i just prompted a browser download
private function overlay2($template, $source_image)
{
$src = imagecreatefromjpeg($source_image);
$dest = imagecreatefrompng($template);
imagecopymerge($dest,$src, 90, 910, 0, 0, 1511, 1075, 100); //have to play with these numbers for it to work for you, etc.
header('Content-Disposition: Attachment;filename=newspaper.png');
header('Content-type: image/png');
imagepng($dest);
imagedestroy($dest);
imagedestroy($src);
}
i had the same problem.
Issue is on PNG 24 bits images. Try to use PNG 16 bits to avoid the problem.
Maybe Gif image will work too (not tested). Codeigniter image library is a nice class.