Ok Something is wrong. I am trying to take a watermark and put it on an image then return the watermarked image to the browser. However if it places the watermark right, it doesn't show all of it, and sometimes it puts blank squares all over. the following is the script in its test form:
<?php
/**
* Display an image to the browser with a watermark
*
* @author Ryan Pallas
* @version v0.5
* @since v0.6
*/
$num = ( ISSET($_GET['num']) && is_numeric($_GET['num']) ) ? (int) $_GET['num'] : '';
/**
* @var int bottom margin
*/
$marginbot = 10;
/**
* @var int right margin
*/
$marginright = 10;
/**
* @var string base image file with full path
*/
//$base = $this->config->item('upload_path') . DIRECTORY_SEPARATOR . $folder . DIRECTORY_SEPARATOR .$img->image_filename . '.' . $img->image_ext;
if( $num == '' || $num == '1' || $num == '3' ) {
$base = 'test' . $num . '.jpg';
} elseif( $num == '2' ) {
$base = 'test' . $num . '.png';
} else {
DIE('Fatal Error');
}
/**
* @var string watermark image with full path
*/
//$watermark = $this->config->item('upload_path') . 'watermark.png';
$watermark = "watermark.png";
/**
* @var array base image info
*/
$baseinfo = getimagesize($base);
list($baseh,$basew,$baset) = $baseinfo;
/**
* @var array watermark image info
*/
$wminfo = getimagesize($watermark);
list($wmh,$wmw) = $wminfo;
if( (($wmw*2) > $basew) || (($wmh*2) > $baseh) ) {
if( $basew > $baseh ) {
$wmscale = ($basew/2)/$wmw;
} else {
$wmscale = ($baseh/2)/$wmh;
}
$newwmw = $wmw*$wmscale;
$newwmh = $wmh*$wmscale;
} else {
$newwmh = $wmh;
$newwmw = $wmw;
}
/**
* determine file type for correct functions
*/
switch($baset)
{
case IMAGETYPE_JPEG:
$create = "imagecreatefromjpeg";
break;
case IMAGETYPE_GIF:
$create = "imagecreatefromgif";
break;
case IMAGETYPE_PNG:
$create = "imagecreatefrompng";
break;
case IMAGETYPE_WBMP:
$create = "imagecreatefromwbmp";
break;
default:
return FALSE;
}
/**
* create image
*/
$baseimg = $create($base);
$wmimg = imagecreatefrompng($watermark);
$newwmimg = imagecreate($newwmw,$newwmh);
imagecopyresized($newwmimg,$wmimg,0,0,0,0,$newwmw,$newwmh,$wmw,$wmh);
imagecopy($baseimg,$newwmimg,($basew-$newwmw-$marginright),($baseh-$newwmh-$marginbot),0,0,$newwmw,$newwmh);
// Output and free memory
header('Content-type: image/png');
imagepng($baseimg);
You can see the examples at http://dev.rdennispallas.com/test.php?num=3 (replace 3 with 2, 1 and remove the query string for 4 different images). The problem is on one image it looks goo except it doesn't show the whole water mark, on the others it is thowing up black squares all over the place so I did something wrong. Hopefully someone can tell me where I screwed up.
TYIA