drakkarnoir
asked on
Centering watermark
Hey guys,
$middle_y = ($canvas_h / 2) - $overlay_h; // $canvas_h is the original picture height, $overlay_h is the overlay height
$middle_x = ($canvas_w / 2) - $overlay_w; // $canvas_w is the original picture width, $overlay_w is the overlay width
imagecopymerge($canvas_img , $overlay_img, $middle_x,$middle_y,0,0, $overlay_w, $overlay_h, $Opacity);
Now, I want to center the overlay over the image...and I thought my math logic would/should work, but it does not.
And also, a function that will generate a thumbnail as well, but portioned to size, so it does not appear distorted.
$middle_y = ($canvas_h / 2) - $overlay_h; // $canvas_h is the original picture height, $overlay_h is the overlay height
$middle_x = ($canvas_w / 2) - $overlay_w; // $canvas_w is the original picture width, $overlay_w is the overlay width
imagecopymerge($canvas_img
Now, I want to center the overlay over the image...and I thought my math logic would/should work, but it does not.
And also, a function that will generate a thumbnail as well, but portioned to size, so it does not appear distorted.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
From what I understand you want to keep the aspect ratio and have a maxium width or height:
<?php
$oldHeight = null; //you'll have to obtain this values
$oldWidth = null;
$maxWidth=200;
$maxHeight=200;
if ($oldHeight > $oldWidth)
{
$newHeight = $maxHeight;
$newWidth = round($oldWidth*$newHeight /$oldHeigh t)
}
else
{
$newWidth = $maxWidth;
$newHeight = round($oldHeight*$newWidth /$oldWidth )
}
//next you'll have to resize the image using this dimmensions
?>
<?php
$oldHeight = null; //you'll have to obtain this values
$oldWidth = null;
$maxWidth=200;
$maxHeight=200;
if ($oldHeight > $oldWidth)
{
$newHeight = $maxHeight;
$newWidth = round($oldWidth*$newHeight
}
else
{
$newWidth = $maxWidth;
$newHeight = round($oldHeight*$newWidth
}
//next you'll have to resize the image using this dimmensions
?>
ASKER
Thanks much.
ASKER