Jump to content


Photo

displaying image on html page????


  • Please log in to reply
4 replies to this topic

#1 digi duck

digi duck
  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 16 September 2006 - 10:28 AM

Hi, i have a site (http://gamesigs.co.uk) where people create images with custom text on top. The image that is created goes to it's own php page and has a long url such as:

http://gamesigs.co.uk/creation.php?color=30&name=josh=75&y=200&angle=0&font=10&size=25&select=255,255,255&color_r=255&color_g=255&color_b=255&submit=Create+My+Sig!

This changes depeding on what settings you give the text.

What i would like to do is to show this image on a html page. I cant specify a html header because i need to use a jpeg header. I think what i need to do is to give the url a name which is the same despite the differences in it and then put this name in a <img src> tag. How would this be done?

Another way i thought of was by doing something along these lines:

<img src="http://gamesigs.co.uk/creation.php?<?php echo $_POST['color','name',etc...]?>"> 
 

Would this work and how should it look???

Here is the code i've been using:

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

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

$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'] <= '47')
{
    $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)+18;

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

imagettftext($im, $size, 0, $hpadding,$vpadding, $textcolor, $font, $name);

}else{

imagettftext($im, $size, $angle, $x, $y, $textcolor, $font, $name);

}

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

Thanks for your help

#2 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 16 September 2006 - 11:20 AM

I believe that should work

Try it
Tell me the problem, I will try tell you the solution

#3 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 16 September 2006 - 11:21 AM

<img src="http://gamesigs.co.uk/creation.php?color=30&name=josh=75&y=200&angle=0&font=10&size=25&select=255,255,255&color_r=255&color_g=255&color_b=255&submit=Create+My+Sig!">

Orio.
Think you're smarty?

(Gone until 20 to November)

#4 448191

448191
  • Staff Alumni
  • Advanced Member
  • 3,545 posts
  • LocationNetherlands

Posted 16 September 2006 - 11:22 AM

You're on the right track.

You just assemble the request string depening on $_POST varaibles.

<?php echo $_POST['color','name',etc...]?>

Won't work though.

I'd say something more along the lines of this:

<?php
echo '<img src="http://gamesigs.co.uk/creation.php?color='.$_POST['color'].'&name='.$_POST['name'].'" />';
?>


#5 448191

448191
  • Staff Alumni
  • Advanced Member
  • 3,545 posts
  • LocationNetherlands

Posted 16 September 2006 - 11:40 AM

Here's an idea: use an associative array in your form to store img properties and values:

<?php
foreach($_POST['imgprops'] as $prop=>$value){
	$uriArr[]= $prop.'='.$value;
}
$uri = 'http://gamesigs.co.uk/creation.php?'.implode('&',$uriArr);
?>
<form id="form1" name="form1" method="post" action="">
  <label>name
  <input type="text" name="imgprops[name]" />
  </label>
  <label>color
  <input type="text" name="imgprops[color]" />
  </label>
  <p>
    <input type="submit" name="Submit" value="Submit" />
  </p>
</form>

A lot of people don't realize you can use associative arrays for get and post index values.

Get example:
?imgprops[color]=blue&imgprops[name]=image1&create=true

print_r($GET) now prints:

Array
(
    [imgprops] => Array
        (
            [color] => blue
            [name] => image1
        )

    [create] => true
)






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users