Forum Moderators: coopster

Message Too Old, No Replies

Image Create From Url

how to use the imagecreatefromjpeg () funtion on a url image.

         

digi_duck

6:47 pm on Apr 20, 2007 (gmt 0)

10+ Year Member



Hi. I have a script that lets people put text on images. I would like to let users choose their own image to put text on by them entering in a url and then the code creating the image from this url. Here is what i have already :


<?php

header("Content-type: image/jpeg");

$name = stripslashes($_GET['name']);

$line2 = stripslashes($_GET['line2']);

$size = stripslashes($_GET['size']);

$centre = stripslashes($_GET['centre']);

$font = 'images/sig_maker/fonts/'.stripslashes($_GET['font']).'.ttf';

$fontcolor['r'] = stripslashes($_GET['color_r']); // font color - RED

$fontcolor['g'] = stripslashes($_GET['color_g']); // font color - GREEN

$fontcolor['b'] = stripslashes($_GET['color_b']); // font color - BLUE

$lines = stripslashes($_GET['lines']);

function arrow($im, $x1, $y1, $x2, $y2, $alength, $awidth, $color){
///
}

if(is_numeric($_GET['color']) && $_GET['color'] >= '1' && $_GET['color'] <= '63')
{
$bgpic = 'images/sig_maker/' . $_GET['color'] . '.jpeg';
}

$im = imagecreatefromjpeg($bgpic);

//Calculate, the centre:

for(;;){

list($image_width, $image_height) = getimagesize($bgpic);
list($left_x, , $right_x) = imagettfbbox($size, 0, $font, $name);
$text_width = $right_x - $left_x;
if($image_width > $text_width+5){

break;

}

$size = $size - .5;
if($size == 1){
die('Script not responding to decreasing font size, in other words: try using less letters.');
}
}
$hpadding = ($image_width - $text_width)/2;
$vpadding = ($image_height/2);

$textcolor = imagecolorresolve($im, $fontcolor['r'], $fontcolor['g'], $fontcolor['b']);
if($centre== 'y'){

imagettftext($im, $size, 0, $hpadding,$vpadding, $textcolor, $font, $name);
imagettftext($im, $size -10,0,$hpadding,$vpadding+$size,$textcolor,$font,$line2);

}else{

imagettftext($im, $size, $angle, $x, $y, $textcolor, $font, $name);
imagettftext($im,$size - 10,$angle,$x,$y+$size,$textcolor,$font,$line2);

}

imagegif($im);
imagedestroy($im);
?>

I know i have to do something to the


$im = imagecreatefromjpeg($bgpic);

but i dont know what. Also if it is possible i would like the user to be able to choose whether to either use the images off my site (selected using a radio button) or by specifying a url.

Thanks. Any help would be much appreciated as i cant seem to work this out at all as i have limited self taught knowledge. Cheers.

dreamcatcher

10:10 am on Apr 25, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi digi_duck,

Did you have any luck sorting this out? You can check out some of the GD notes on the PHP [uk.php.net] website. Or try the docs on the GD [boutell.com] site itself.

dc

digi_duck

5:05 pm on Apr 25, 2007 (gmt 0)

10+ Year Member



no after researching it with my host i realised that fopen function is disabled so i cant open images from another location. Thanks anyway.