This will be quite difficult to understand, because it does not have a very dynamic explanation. I will try to be as clear as possible!
I want to create a letter generator that looks like this:
This is the site: link
But as everything with me has to be difficult the creation of the image went wrong. I do not know where or why the code does not run perfectly, and no place reports error.
I've reviewed the code several times and can not seem to find the error.
This is what happens when I run: link
<?php
$date = time();
//header("Content-disposition: attachment; filename=$date.png");
header('Content-type: image/png');
error_reporting(10);
$text = $_GET['text'];
$folder = $_GET['folder'];
$spacing = $_GET['space'];
if($spacing == ""){
$spacing = 0;
}
if($text == ""){
$text = "Habbo";
$spacing = -2;
}
if($folder == ""){
$folder = "wabbo4";
}
if($spacing == ""){
if($folder == "1"){
$spacing = 1;
}
if($folder == "2"){
$spacing = 1;
}
if($folder == "3"){
$spacing = -1;
}
}
$folder = preg_replace("/[^a-zA-Z0-9s]/", "", $folder);
if(!is_dir($folder)){
$folder = "1";
}
$length = strlen($text);
for($i = 0; $i < $length; $i++){
$letter = substr($text, $i, 1);
if($letter == "+"){
$imgwidth = $imgwidth+5+$spacing;
}else{
if (preg_match("/[a-z]/", $letter)) {
$letterimg = imagecreatefrompng("".$folder."/".$letter.".png");
$letterimgwidth = ImageSX($letterimg);
$letterimgheight = ImageSY($letterimg);
$yoffset = 21-$letterimgheight;
$imgwidth = $imgwidth+$letterimgwidth+$spacing;
}elseif (preg_match("/[A-Z]/", $letter)){
$letter = strtolower($letter);
$letterimg = imagecreatefrompng("".$folder."/".$letter.".png");
$letterimgwidth = ImageSX($letterimg);
$letterimgheight = ImageSY($letterimg);
$yoffset = 21-$letterimgheight;
$imgwidth = $imgwidth+$letterimgwidth+$spacing;
}else{
$imgwidth = $imgwidth+5;
}
}
}
$imgwidth = $imgwidth-$spacing+1;
$im = imagecreate($imgwidth, $letterimgheight+1);
$overimageheight = $letterimgheight+1;
$background = imagecolorallocatealpha($im, 0, 255, 0, 0);
imagecolortransparent($im, $background);
$xcoord = 1;
for($i = 0; $i < $length; $i++){
$letter = substr($text, $i, 1);
if($letter == "+"){
$xcoord = $xcoord+5+$spacing;
}else{
if (preg_match("/[a-z]/", $letter)) {
$letterimg = imagecreatefrompng("".$folder."/".$letter.".png");
$letterimgwidth = ImageSX($letterimg);
$letterimgheight = ImageSY($letterimg);
$yoffset = $overimageheight-$letterimgheight;
if($letter == "g" || $letter == "j" || $letter == "q" || $letter == "p" || $letter == "y"){
}
imagecopy($im, $letterimg, $xcoord, $yoffset, 0, 0, $letterimgwidth, $letterimgheight);
$xcoord = $xcoord+$letterimgwidth+$spacing;
}elseif (preg_match("/[A-Z]/", $letter)){
$letter = strtolower($letter);
$letterimg = imagecreatefrompng("".$folder."/".$letter.".png");
$letterimgwidth = ImageSX($letterimg);
$letterimgheight = ImageSY($letterimg);
$yoffset = $overimageheight-$letterimgheight;
imagecopy($im, $letterimg, $xcoord, $yoffset, 0, 0, $letterimgwidth, $letterimgheight);
$xcoord = $xcoord+$letterimgwidth+$spacing;
}else{
$xcoord = $xcoord+5;
}
}
}
header("Content-type: image/png");
imagepng($im);
imagedestroy($im);
?>
In case folder would be the folder where the letters are, explaining better, the user writes the testo and the folder would be the source where would get the letter a, b, c ... space would be the space between the letters because some fonts need a larger space.
follow image:
The result as I said would be the text formed by the letters of a certain source, but it error, DOES NOT REPORT ANY ERROR IN PHP.
I need this help, I've never been good with imagecreate (); I hope you have been clear with my problem.