Jump to content

Recommended Posts

hi everyone,

i need help to make this script work.

 

got files from http://alvarotrigo.com/blog/using-php-gd-library-to-write-text-over-images-using-truetype-fonts/

the demo is working but mine is not :)

 

here is my writingOverImage.php file

(other files same https://github.com/alvarotrigo/PHP-Backend/tree/master/textPainter)

 

full my script here https://www.dropbox.com/s/vpnup95p572s1s6/textPainter.zip?dl=0

thank you.

<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Floating window with tabs</title>
 
<style>
 
/*
This defines the workspace where i place the demo.
*/
#container {
    text-align: left;
    background: #FFF;
    width: 865px;
    margin: 20px auto;
    padding: 20px;
    border-left: 1px solid #CCC;
    border-right: 1px solid #CCC;
    -moz-box-shadow: 0px 0px 10px #BBB;
    -webkit-box-shadow: 0px 0px 10px #BBB;
    box-shadow: 0px 0px 10px #BBB;
}
</style>
         
</head>
<body>
 
 
<div id="container">

<?php 
    if($_POST["sending"]=="yes"){
        if(strlen($_POST["text"]<50)){
            echo '
                <img id="imgFinal" src="writingOverImage.php?size=50&text='.$_POST["text"].'" />
 
                <img id="imgFinal" src="writingOverImage.php?x=right&y=center&size=30&r=74&g=50&b=170&text='.$_POST["text"].'" />
 
                <img id="imgFinal" src="writingOverImage.php?x=left&y=bottom&size=90&text='.$_POST["text"].'" />
            ';
        }
        else{
            echo "The text is too large for my demo!! ";
        }
    }
    else{
        echo '
            <img id="imgFinal" src="writingOverImage.php?size=50&text=Hello world!!" />
        ';
         
    }
?>

<form name="formulario" action="" method="post" class="contactoFormulario">
        <div class="caja"><input type="text" name="text" />Text you want to write over the image</div>
 
        <button class="botonFormulario" type="submit" name="Submit" value="Enviar" />Generate image</button>
        <input type="hidden" name="sending" value="yes" />
    </form>
</div>
 
</body>
</html>

<?php
require_once 'class.textPainter.php';
 
$x = $_GET["x"];
$y = $_GET["y"];
 
$R = $_GET["r"];
$G = $_GET["g"];
$B = $_GET["b"];
 
$size = $_GET["size"];
 
$text = $_GET["text"];
 
 
$img = new textPainter('./imgs/writingOverImage.jpg', $text, './Franklin.ttf', $size);
 
if(!empty($x) && !empty($y)){
    $img->setPosition($x, $y);
}
 
if(!empty($R) && !empty($G) && !empty($B)){
    $img->setTextColor($R,$G,$B);
}
 
$img->show();

?>
Edited by PHPnewbie15
Link to comment
https://forums.phpfreaks.com/topic/298305-write-text-over-images/
Share on other sites

In writingOverImage.php you cannot have your html/form and the php code for creating the image in the same file. They must in separate files like so

 

form.php

<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Floating window with tabs</title>
 
<style>
 
/*
This defines the workspace where i place the demo.
*/
#container {
    text-align: left;
    background: #FFF;
    width: 865px;
    margin: 20px auto;
    padding: 20px;
    border-left: 1px solid #CCC;
    border-right: 1px solid #CCC;
    -moz-box-shadow: 0px 0px 10px #BBB;
    -webkit-box-shadow: 0px 0px 10px #BBB;
    box-shadow: 0px 0px 10px #BBB;
}
</style>
         
</head>
<body>
 
 
<div id="container">

<?php 
    if($_POST["sending"]=="yes"){
        if(strlen($_POST["text"]<50)){
            echo '
                <img id="imgFinal" src="writingOverImage.php?size=50&text='.$_POST["text"].'" />
 
                <img id="imgFinal" src="writingOverImage.php?x=right&y=center&size=30&r=74&g=50&b=170&text='.$_POST["text"].'" />
 
                <img id="imgFinal" src="writingOverImage.php?x=left&y=bottom&size=90&text='.$_POST["text"].'" />
            ';
        }
        else{
            echo "The text is too large for my demo!! ";
        }
    }
    else{
        echo '
            <img id="imgFinal" src="writingOverImage.php?size=50&text=Hello world!!" />
        ';
         
    }
?>

<form name="formulario" action="" method="post" class="contactoFormulario">
        <div class="caja"><input type="text" name="text" />Text you want to write over the image</div>
 
        <button class="botonFormulario" type="submit" name="Submit" value="Enviar" />Generate image</button>
        <input type="hidden" name="sending" value="yes" />
    </form>
</div>
 
</body>
</html>

writingOverImage.php

<?php
require_once 'class.textPainter.php';

$x = $y = $R = $G = $B = null;

if(isset($_GET['x'], $_GET['y']))
{
   $x = $_GET["x"];
   $y = $_GET["y"];
}

if(isset($_GET['r'], $_GET['g'], $_GET['b']))
{ 
    $R = $_GET["r"];
    $G = $_GET["g"];
    $B = $_GET["b"];
}

$size = $_GET["size"];
$text = $_GET["text"];
 
 
$img = new textPainter('./imgs/writingOverImage.jpg', $text, './Franklin.ttf', $size);
 
if(!empty($x) && !empty($y)){
    $img->setPosition($x, $y);
}
 
if(!empty($R) && !empty($G) && !empty($B)){
    $img->setTextColor($R,$G,$B);
}
 
$img->show();

NOTE: if your are using PHP version 5.3 or newer then your need to make the following changes to class.textPainter,php.

 

Line 78 needs to be changed to

                imagejpeg($this->img, NULL, $this->jpegQuality);

Line 154 needs to be changed to

    	$this->format = preg_replace("/.*\.(.*)$/","\\1",$this->imagePath);
Edited by Ch0cu3r
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.