Jump to content

trying to place text on an image


aebstract

Recommended Posts

<?php

$file = 'image.jpg';
$image = imagecreatefromjpeg($file);
list($width, $height) = getimagesize($file);

$font = 'arial.ttf';
$size = 8;

$title = 'Last played:';
$artist = 'artist name';
$song = 'song name';

$colorHex = '000000';

list($tr, $tg, $tb) = sscanf($colorHex, '%02X%02X%02X');

$textColor = imagecolorallocate($image, $tr, $tg, $tb);

imagettftext($image, $size, 0, 4, $height-29, $textColor, $font, trim($title));
imagettftext($image, $size, 0, 4, $height-17, $textColor, $font, trim($song));
imagettftext($image, $size, 0, 4, $height-5, $textColor, $font, trim($artist));

imagejpeg($image, 'image2.jpg', 95);

?>

Trying to place text on top of an existing image and create a new image from that. Once I figure out how to reference values from another website, it should be able to update automatically with certain bits of information.. as it changes on that site. Right now it isn't working really at all. Could someone possibly help on this?

Link to comment
https://forums.phpfreaks.com/topic/134054-trying-to-place-text-on-an-image/
Share on other sites

hows this?:

 

<?php
//use existing image as a canvas
$myImage = ImageCreateFromPNG ("baseimage.png");

//allocate the color white
$white = ImageColorAllocate ($myImage, 255, 255, 255);

//draw on the new canvas
ImageFilledEllipse($myImage, 100, 70, 20, 20, $white);
ImageFilledEllipse($myImage, 175, 70, 20, 20, $white);
ImageFilledEllipse($myImage, 250, 70, 20, 20, $white);

//output the image to the browser
header ("Content-type: image/png");
ImagePNG($myImage);

//clean up after yourself
ImageDestroy($myImage);
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.