sanders
sanders

Reputation: 10898

merge images with text

Is there a way to put text on a png and then merge it wit a jpg / gif image?

Upvotes: 3

Views: 6543

Answers (3)

Ólafur Waage
Ólafur Waage

Reputation: 70001

Here's how i do it.

/* load the image */
$im = imagecreatefrompng("image.png");

/* black for the text */
$black = imagecolorallocate($im, 0, 0, 0);

/* put the text on the image */
imagettftext($im, 12, 0, 0, 0, $black, "arial.ttf", "Hello World");

/* load the jpg */
$jpeg = imagecreatefromjpeg("image.jpeg");

/* put the png onto the jpeg */
/* you can get the height and width with getimagesize() */
imagecopyresampled($jpeg,$im, 0, 0, 0, 0, $jpeg_width, $jpeg_height, $im_width, $im_height);

/* save the image */
imagejpeg($jpeg, "result.jpeg", 100);

This is a pretty simple example though.

Upvotes: 1

edoloughlin
edoloughlin

Reputation: 5901

You don't say what language you're using, but Imagemagick has APIs in a few different languages (http://www.imagemagick.org/script/api.php).

Upvotes: 0

deresh
deresh

Reputation: 510

you can draw any text in or on image with gd using ttf or type1 fonts ( if its enabled in gd in php).

http://hr.php.net/manual/en/image.examples-watermark.php

Upvotes: 3

Related Questions