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
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);
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.