Jump to content

Text within a PNG image


MasterACE14

Recommended Posts

Afternoon Everyone,

 

I have a script which basically puts in 2 words into a PNG image, what I want to do is, center the text horizontally, set the font to Arial, and make the text slightly transparent.

 

here is my script:

<?php

// variables
$testing = "Alpha Testing";

$image = "http://www.crikeygames.com.au/conflictingforces/images/conflicting_forces_header.png";  
$im = imagecreatefrompng($image); 
$wc = ImageColorAllocate ($im, 255, 255, 255);  
$red = ImageColorAllocate ($im, 255, 0, 0); 
ImageString($im, 3, 260, 2, $testing, $wc);  
header("Content-Type: image/png");  
Imagepng($im,'',100);  
ImageDestroy ($im); 

?>

 

any help is greatly appreciated  :)

 

Regards ACE

Link to comment
Share on other sites

$string = "Your Text Here";
$im     = imagecreatefrompng("bg.png");
$orange = imagecolorallocate($im, 0, 0, 0);
$px     = (imagesx($im) - 7.5 * strlen($string)) / 2;
imagestring($im, 3, $px, 9, $string, $orange);
imagepng($im);
imagedestroy($im);

 

I didn't really modify this code, but you should be able to, to get it to say what you want.  It centers the text.  It's also the wrong font.  I'm not sure how to change that.  Sorry.  Hope this helps a little.

Link to comment
Share on other sites

I've now got it centered nicely, But I still don't know how to make it transparent(the string) and make it Arial font?

 

current code:

<?php

// variables
$testing = "Alpha Testing";

$image = "http://www.crikeygames.com.au/conflictingforces/images/conflicting_forces_header.png";  
$im = imagecreatefrompng($image); 
$wc = ImageColorAllocate ($im, 255, 255, 255);  
$red = ImageColorAllocate ($im, 255, 0, 0);
$px = (imagesx($im) - 7.5 * strlen($testing)) / 2;
ImageString($im, 3, $px, 16, $testing, $wc);  
header("Content-Type: image/png");  
Imagepng($im,'',100);  
ImageDestroy ($im); 

?>

 

Regards ACE

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.