PDA

View Full Version : ---- Imagecreatefromjpeg($url) ----


digi duck
04-20-2007, 07:42 PM
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.

Fumigator
04-20-2007, 08:58 PM
http://us2.php.net/manual/en/function.imagecreatefromjpeg.php

Read the "tip" on that page-- it's shaded in blue just a bit from the top of the page. Your first step is making sure your server does fopen wrappers.

digi duck
04-21-2007, 09:46 PM
ok thanks for your help.
I looked it up and realised my host suddenly and without warning decided to disable fopen so i think this is why it isnt working, Only local files can be opened. Is there any way to get around this?

Fumigator
04-22-2007, 09:27 PM
Find a new hosting company.