Upgraded Server

Man I hate it when I have to upgrade things, they always fuck up something. Right now, I spent hours trying to make something work. The story starts when I need to run a .jar file on the server which basically does one simple thing, takes an image and overlays text on it. Which to be honest it seems idiotic, the dev I am working with doesn't use PHP, but since I am NOT a dev, I thought I would go about it, to make things comfortable, I had to install Tomcat 7.0 so JRE files can run.

Now, while doing that I saw that I was running PPH 5.3 which is EOL, as in outdated and NOT good. So, I thought fuck it, I knew that PHP 5.4 or greater breaks one key software that I use, but I already bought a newer version, so I was confident everything would work.

It didn't, got three build fails and finally resorted to:

Apache 2.2
Php 5.4
Tomcat 7.0

Other variations just failed, or weren't good. Now, since I have found what I am looking for via PHP

http://stackoverflow.com/questions/7569885/overlay-image-with-text-and-convert-to-image

Srsly, it's just.. err damn. I will remove tomcat *like fuck Java* and try apache 2.4 if possible.

If you see things breaking let me know.


Also, Slarti, the task is pretty simple for the script.

A) Parameter is passed via Query string,
B) A new image file is created and it has TEXT = name, as in name of the person, and the file is saved by the same name, sure it will have duplicates but it's easier for the file to be ron.jpg.

I am going to play with that script tomorrow, pretty sure we have GD and freetype fonts. But Also did install the font I would be using it's TTF btw.

Anyway, it's 3 am I am tired, take care mates :)

Comments

  • SlartibartfastSlartibartfast Global Moderator -__-
    It's not as simple as you'd think. images formats can be complicated. You need to turn the image into an editable object (say an array) and add data (the text) to it without corrupting it. 

    I took an OpenGL class once. It can get very mathy. 
  • SlartibartfastSlartibartfast Global Moderator -__-
    edited June 2015
    <?php
    //addtext.php
    //Set the Content Type
    header('Content-type: image/jpeg');
    $jpg_path = $_GET["image"];
    $text = $_GET["text"];
    $jpg_image = imagecreatefromjpeg($jpg_path);

    //////////////////////////////////////////////////////
    // Allocate Colors
    $white = imagecolorallocatealpha($jpg_image, 255, 255, 255, 0);
    $black = imagecolorallocatealpha($jpg_image, 0, 0, 0, 0);
    // add colors here.

    //padding of textbox in px
    $padding = 10;

    //size of text
    $textsize = 25;

    //text color
    $textcolor = $white;
    //////////////////////////////////////////////////////

    // Allocate A Color For The Text
    $white = imagecolorallocate($jpg_image, 255, 255, 255);

    // Set Path to Font File
    $font_path = "font.TTF";

    //get dimensions
    $tb = imagettfbbox($textsize, 0, 'font.TTF', $text);

    //get dimensions of image
    list($x0, $y0) = getimagesize($jpg_path);

    //find (center, bottom)
    $x = ceil(($x0 - $tb[2]) / 2);
    $y = $y0-$padding;

    // Print Text On Image
    imagettftext($jpg_image, $textsize, 0, $x, $y, $textcolor, $font_path, $text);

    //create filename
    $filename = preg_replace('/\s+/', '', $text); //remove all whitespaces
    $filename = $filename.".jpg";

    // Save image to folder
    imagejpeg($jpg_image, $filename, 100);

    // Clear Memory
    imagedestroy($jpg_image);
    ?>
    then:
    totseans.com/conv/addtext.php?image=image.jpg&text=This is a test
    will create thisisatest.jpg in the folder

    EDIT: fixed to always set text at (center,bottom).
  • SlartibartfastSlartibartfast Global Moderator -__-
    edited June 2015

    <?php
    //genimage.php
    //Set the Content Type
    header('Content-type: image/jpeg');

    /////////////////////////////////////////////////////////////////////
    //Set text size
    $textsize = 15; // this will be 1 smaller.

    // Set Path to Font File
    $font_path = "font.TTF";

    // Set Text to Be Printed On Image
    $text = $_GET["text"];

    //padding of image in px
    $padding = 10;

    /////////////////////////////////////////////////////////////////////

    //get dimensions
    $tb = imagettfbbox($textsize, 0, 'font.TTF', $_GET["text"]);

    // Create Image
    $im = imagecreatetruecolor($tb[2]+$padding, -1*$tb[7]+$padding);

    // Allocate Colors
    $white = imagecolorallocate($im, 255, 255, 255);
    $black = imagecolorallocate($im, 0, 0, 0);

    imagefilledrectangle($im, 0, 0, $tb[2]+$padding, -1*$tb[7]+$padding, $white);


    // Print Text On Image
    $x = ceil(($tb[2]+$padding - $tb[2]) / 2);
    $y = -1*$tb[7]+$padding/2;
    imagettftext($im, $textsize-1, 0, $x, $y, $black, $font_path, $text);

    //create filename
    $filename = preg_replace('/\s+/', '', $text); //remove all whitespaces
    $filename = $filename.".jpg";

    // Save image to folder
    imagejpeg($im, $filename, 100);

    // Clear Memory
    imagedestroy($im);
    ?>

    This will generate a white background jpeg and black text from nothing with:
     totseans.com/conv/genimage.php?text=This is a test
    called thisisatest.jpg
  • SlartibartfastSlartibartfast Global Moderator -__-
    I had fun doing those! 
  • DfgDfg Admin

    I had fun doing those! 

    THANK YOU MATE, I FUCKING LOVE YOU
  • DfgDfg Admin
    Upgrading to Apache 2.4, and PHP 5.5
  • DfgDfg Admin
    Upgrade failed, Apache 2.4 kills Ngnix :(. But yeah at least it's 2.2 with PHP 5.5
  • SlartibartfastSlartibartfast Global Moderator -__-
    2.2 is still the recommended version I think. 
  • DfgDfg Admin
    Oh good, upgrading vanilla.
Sign In or Register to comment.