Page 1 of 1

[SOLVED] GD being stupid

Posted: Sat Jun 12, 2004 10:20 pm
by dull1554

Code: Select all

<?php
  header("Content-type: image/jpeg");
  $im = imagecreate(400, 30);
  $white = imagecolorallocate($im, 255, 255, 255);
  $black = imagecolorallocate($im, 0, 0, 0);
  
  // Replace path by your own font path
  imagettftext($im, 20, 0, 10, 20, $black, "/hotpizza.ttf",
  "Testing... Omega: &#937;");
  imagejpeg($im);
  imagedestroy($im);
?>
when i run this i get this error

Code: Select all

The image “http://yoursitenamehere.com/gdttf.php” cannot be displayed, because it contains errors.
any thoughts?

Posted: Sat Jun 12, 2004 10:57 pm
by markl999
Try doing 'view source' in your browser, it should tell you what's wrong.

Posted: Sun Jun 13, 2004 3:52 am
by launchcode
At a glance I bet that font path is wrong too - comment that bit out, does it work now? If so - it cannot find the TTF file.

Posted: Sun Jun 13, 2004 7:34 am
by wwwapu
Shouldn't the path be "./hotpizza.ttf" dot meaning current directory?

Posted: Sun Jun 13, 2004 9:51 am
by dull1554
yep it works now, thanks a bunch

Posted: Sun Jun 13, 2004 10:40 am
by Joe
Im just curious here, Is that code for creating random images as I am sure I have seen something like it before but I just cannot put my finger on it. Is there any particular references to this sort of code as I find it very interesting.

All the best!


Joe 8)

Posted: Sun Jun 13, 2004 9:01 pm
by dull1554
well i was expirmenting with this a while to make a security image, and maybe i should post it in the snippet section but here it is

securityGD.php

Code: Select all

function arraygen($length){
    $letters = array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z');
    $numbers = array('0','1','2','3','4','5','6','7','8','9');
    srand((double)microtime()*1000000);
    for($index = 0; $index < $length; $index++){
    for($i = 1; $i < 9; $i++)
    {
    $rand = mt_rand(1,2);
    if($rand == 1)
    {
    $q = mt_rand(1,26);
    $char[$i] = $letters[$q];
    }
    if($rand == 2)
    {
    $q = mt_rand(1,10);
    $char[$i] = $numbers[$q];
    }
    }
    $array[$index] = "_ ".$char[1]." ".$char[2]." ".$char[3]." ".$char[4]." ".$char[5]." ".$char[6]." ".$char[7]." ".$char[8];
    }
    return $array;
}




    srand((double)microtime()*1000000);
    $rand = mt_rand(1, 100);
    $array = arraygen($rand);
    $string = $array[mt_rand(1, $rand)];
    $stringpieces = explode(" ", $string);
    $_SESSION['secret_string'] = $stringpieces[1].$stringpieces[2].$stringpieces[3].$stringpieces[4].$stringpieces[5].$stringpieces[6].$stringpieces[7].$stringpieces[8];
    header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
    header("Expires: Thu, 19 Nov 1981 08:52:00 GMT");
    header("Pragma: no-cache");
    header("Content-type: image/png");
    $img_handle = imagecreatefrompng("secure.png");
    $back_color = ImageColorAllocate ($img_handle, 64, 131, 183);
    for ($i = 1; $i < 9;$i++) {
        ImageTTFText ($img_handle, mt_rand(10,20) / 96 * 72, 0, 15 * $i, 18, ImageColorAllocate ($img_handle, 255, 255, 255), dirname( __FILE__ )."/verdana.ttf",  $stringpieces[$i]);
    }
    Imagepng($img_handle);

Posted: Sun Jun 13, 2004 9:02 pm
by dull1554
i'm sure the code could be cleaned up a bit, jusr because i made this a while back......i dont know....do with it what you wish.....