AdRock Posted August 1, 2008 Share Posted August 1, 2008 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 More sharing options...
Barand Posted August 1, 2008 Share Posted August 1, 2008 image tag in main doc <img src='myimage.php?heading=XYZ'> In your image script (myimage.php) $heading = $_GET['heading']; Print $heading in the image Link to comment https://forums.phpfreaks.com/topic/117652-is-this-possible-with-strreplace/#findComment-605134 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.