Solved

Centering watermark

Posted on 2004-03-28
4
236 Views
Last Modified: 2012-05-04
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
Comment
Question by:drakkarnoir
  • 2
  • 2
4 Comments
 
LVL 6

Accepted Solution

by:
CosminB earned 500 total points
Comment Utility
try:
 $middle_y = ($canvas_h  - $overlay_h)/ 2;
 $middle_x = ($canvas_w - $overlay_w) / 2;
0
 

Author Comment

by:drakkarnoir
Comment Utility
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
 
LVL 6

Expert Comment

by:CosminB
Comment Utility
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
 

Author Comment

by:drakkarnoir
Comment Utility
Thanks much.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This article discusses how to create an extensible mechanism for linked drop downs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now