Centering watermark

Posted on 2004-03-28
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.
Question by:drakkarnoir
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2

Accepted Solution

CosminB earned 500 total points
ID: 10702007
 $middle_y = ($canvas_h  - $overlay_h)/ 2;
 $middle_x = ($canvas_w - $overlay_w) / 2;

Author Comment

ID: 10708349
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.

Expert Comment

ID: 10710558
From what I understand you want to keep the aspect ratio and have a maxium width or height:
$oldHeight = null; //you'll have to obtain this values
$oldWidth = null;
if ($oldHeight > $oldWidth)
  $newHeight = $maxHeight;
  $newWidth = round($oldWidth*$newHeight/$oldHeight)
  $newWidth = $maxWidth;
  $newHeight = round($oldHeight*$newWidth/$oldWidth)
//next you'll have to resize the image using this dimmensions

Author Comment

ID: 10728936
Thanks much.

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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 …

726 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