Forum Moderators: coopster

Message Too Old, No Replies

adding unique stuff onto images

         

surrealillusions

12:52 pm on Dec 17, 2008 (gmt 0)

10+ Year Member



Hi all,

Thought it might be best to ask here, rather than search for something i dont quite know what to look for.

What i would like to do, is to add a unique identifier to an image each time the page is loaded. Like a voucher number or similiar, so each time the page is loaded with the image on, then that random number changes and the number cannot be repeated (does that make sense?), so if someone loads up and the number is 94, then that number can never appear again.

I have GD library installed so i have access to that for image stuff.

Any help would be appreciated.

base

1:04 pm on Dec 17, 2008 (gmt 0)

10+ Year Member



and what would would be the purpose for doing that?

disable hotlinking?

henry0

1:35 pm on Dec 17, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



for example:
<?php

//get img from its dir, here we use gif, same with jpeg
$im = imagecreatefromgif('where the img is loaded/img.gif');

//get the image size
$w = imagesx($im);
$h = imagesy($im);

// example
$input="AAAAAAAAA";

// next create that text and position it
$text = imagecreatetruecolor($w, $h);
//example of location: text at the top left
imagestring($text, 5, 0, 0, $input, 0x0000FF);

// merge the two components
//set opacity to 50%
imagecopymerge($im, $text, 0, 0, 0, 0, $w, $h, 50);

// output the new img
header('Content-Type: image/gif');
imagegif($im);
imagedestroy ($text);
imagedestroy($im);
?>

surrealillusions

2:46 pm on Dec 17, 2008 (gmt 0)

10+ Year Member



henry, thanks, its what i am looking for.

However, i cant get black text, and the image quality of the output is very poor (solved by using png instead of jpg).

henry0

3:24 pm on Dec 17, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



from my library

check this one with image quality set at 100 (the max)

<?php
$string = "AAAA";
$dir="../default/";
$id=24;
$ext=".jpg";
$dir=$dir.$id.$ext;
$im = imagecreatefromjpeg("../default/a.jpg");
$orange = imagecolorallocate($im, 18, 252, 161);
$px = (imagesx($im) - 9* strlen($string)) / 2;
imagestring($im, 3, $px, 9, $string, $orange);
imagejpeg($im, $dir, 100);

// then if needed use copy ()
/*
$src=$b;
$dest="../default/$b.'.jpg' ";
copy($src, $dest);
if(!copy($src, $dest))
{echo"no";}
*/
imagedestroy($im);
?>

got to run ...