[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 300
  • Last Modified:

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.
0
drakkarnoir
Asked:
drakkarnoir
  • 2
  • 2
1 Solution
 
CosminBCommented:
try:
 $middle_y = ($canvas_h  - $overlay_h)/ 2;
 $middle_x = ($canvas_w - $overlay_w) / 2;
0
 
drakkarnoirAuthor Commented:
Thank you much CosminB, could you help me with the second part as well? Like a thumbnail generator that constrains sizes much like Photoshop Image Size function, so it does not look distorted.
0
 
CosminBCommented:
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/$oldHeight)
}
else
{
  $newWidth = $maxWidth;
  $newHeight = round($oldHeight*$newWidth/$oldWidth)
}
//next you'll have to resize the image using this dimmensions
?>
 
0
 
drakkarnoirAuthor Commented:
Thanks much.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now