Jump to content

Is this possible with strreplace


AdRock

Recommended Posts

I have a couple questions that are linked to the same topic

 

first one is, i have some code that converts a string of text and outputs it as an image.  How would i change the text to be output so i can pass a parameter so i can use the same code to output different images with different text?

<?php
header ("Content-type: image/png");
$handle = ImageCreate (130, 50) or die ("Cannot Create image");
$bg_color = ImageColorAllocate ($handle, 255, 255, 255);
$txt_color = ImageColorAllocate ($handle, 0, 0, 0);
ImageTTFText ($handle, 20, 0, 30, 40, $txt_color, "/Fonts/porkys.ttf", "porkys");
ImagePng ($handle);
?> 

I would have to change 'porkys' to a variable so i presume i would put the code into a function with a variable as a parameter.

 

I did try this but i get an error

The image cannot be displayed becuase it contains errors

<?php
function convertToPng($heading) {
header ("Content-type: image/png");
$handle = ImageCreate (130, 50) or die ("Cannot Create image");
$bg_color = ImageColorAllocate ($handle, 255, 255, 255);
$txt_color = ImageColorAllocate ($handle, 0, 0, 0);
ImageTTFText ($handle, 20, 0, 30, 40, $txt_color, "/Fonts/porkys.ttf", $heading);
ImagePng ($handle);
}
?>

<img src="<?php convertToPng($heading); ?>"

 

The second question is, if that works, is it possible to do some sort of strreplace of a <h1> tag and replace it with what is in that image?  I would like to replace all <h1> with the image of the text instead

Link to comment
https://forums.phpfreaks.com/topic/117652-is-this-possible-with-strreplace/
Share on other sites

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.