ThinkingInBits
ThinkingInBits

Reputation: 11482

How to create watermark with imagemagick

I'm trying to create a watermark with ImageMagick however, the guides on layering are pretty daunting. Basically I'll have one base image say "base.jgp" and an overlay image say "overlay.jpg". Overlay.jpg would be smaller than base.jpg. Which exec command would I run to place overlay centered on top of base.jpg?

Thanks!

Upvotes: 2

Views: 5761

Answers (3)

user2455079
user2455079

Reputation: 418

$image = new Imagick();
$image->readImage("image.jpg");

// Open the watermark
$watermark = new Imagick();
$watermark->readImage("watermark.png");

// Overlay the watermark on the original image
$image->compositeImage($watermark, imagick::COMPOSITE_OVER, 0, 0);

// send the result to the browser
header("Content-Type: image/" . $image->getImageFormat());

Upvotes: 1

ThinkingInBits
ThinkingInBits

Reputation: 11482

shell_exec("composite -gravity center ./images/watermark_horizontal.png {$this->path} {$this->path}");

Here we go

Upvotes: 4

Pekka
Pekka

Reputation: 449803

Check out ImageMagick examples, especially the Compositing Images chapter. It has a number of ready-made real-world examples.

Upvotes: 2

Related Questions