Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 277
  • Last Modified:

How to handle equals char when laying text over images with GD and imagecreatefrompng

Hey there, I have the following:

$str1 = "=I=Test";

And some image code:

$dest_img = @imagecreatefrompng("minisigback.png");
imagettftext($dest_img, 20, 0, 16, 24, $black, $font_file, $str1);

Problem is it fails (not surprisingly) with the = char when found in $str1. I thought of using addslashes, but = is not a trigger for addslashes. Any idea?
0
Dodger42
Asked:
Dodger42
1 Solution
 
Dodger42Author Commented:
OK I found the problem and fixed that first part, but now I have the following problem. Because I want to save the image as $str1.png it fails due to the equals char. I made a workaround:

md5($str1);

that gives me a unique string that is acceptable as filename, buts its long and hard to remember.

Any better ideas?
0
 
mnb93Commented:
$str1 = preg_replace('/[^a-z0-9]/i','',$str1); //Removes all but a-z A-Z 0-9
0
 
Dodger42Author Commented:
Hmm ok. I just used that, and although it isn't perfect, the output filename is much more legible than the md5. Will leave this open for a little longer, but this will work for me if need be.

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Richard QuadlingSenior Software DeverloperCommented:
Replace = with _ maybe? Why does the filename have to contain an = sign?
0
 
stuartc1Commented:
to just remove the = use:
$str1 = string_replace("=", "", $str1);
0
 
Dodger42Author Commented:
Sorry I didnt explain the problem well enough. $str1 actually derives from a log file of a game. It may contain all sorts of strange characters and I cannot change that. The script will generate an image file. For ease of use, that image file would be $str1.png (intuitive). It probably a limitation of windows filenames and php that i cant work around too easily.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now