Jump to content

imagecreate failing


Mahngiel

Recommended Posts

Greetings, been a while since I've been here.  I'm having a helluva problem using this imagecreate, as I am not able to output an actual image file.  The output is here: www.mahngiel.com/kat/img2.php and my coding is below.

(don't worry, nobody can see your IP except yourself, and it is not logged)

 

Cheers!

 

<?php

//Validate IP
if (!empty($_SERVER['HTTP_CLIENT_IP'])){
  $ip=$_SERVER['HTTP_CLIENT_IP'];
//Is it a proxy address
}elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){
  $ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
}else{
  $ip=$_SERVER['REMOTE_ADDR'];
}

//Original Image for background
$img = imagecreatefrompng('ipfun.png');
imagealphablending($img, true);

//Colors
$black = imagecolorallocate($img, 0, 0, 0);
$gold = imagecolorallocate($img, 255, 215, 0);
$red = imagecolorallocate($img, 178, 34, 34);

//Border
imagesetthickness($img, 2);
imagerectangle($img, 0, 2, 98, 98, $black);

//Shapes
imageline($img, 15,31, 80,31, $gold);
imagerectangle($img, 4,80, 97,70, $red);

//Strings
$font_file = '../poll/mahngiel.ttf';
imagefttext($img, 13, 0, 15, 28, $black, $font_file, 'Your IP:');
imagefttext($img, 32, 350, 42, 63, $red, $font_file, '!');
imagefttext($img, 11, 0, 4, 80, $gold, $font_file, $ip);

//Output
header("Content-Type: image/png");
imagepng($img);
imagedestroy($img);

?>

Link to comment
https://forums.phpfreaks.com/topic/240065-imagecreate-failing/
Share on other sites

I guess I was hoping for more of an image extension in the output. Notice my page output still ends in PHP, whereas my muse ends in a .jpg and is easily referred to external calls.  http://www.danasoft.com/vipersig.jpg

 

vipersig.jpgimg2.php.png

 

 

I've tried imagepng($img, $dest), which does output to disk, but it will no longer process the script.

Link to comment
https://forums.phpfreaks.com/topic/240065-imagecreate-failing/#findComment-1233358
Share on other sites

Hmm. Yes, i've noticed i could wrap it in an image tag with the .php extention - but I'm still missing a piece of the puzzle.  I'm trying to use this as an avatar, which requires the link to have the extention png/jpg/etc etc.  I can use the php-image i posted above, and it performs as it should; but I've yet to figure how I can duplicate that myself.

Link to comment
https://forums.phpfreaks.com/topic/240065-imagecreate-failing/#findComment-1233409
Share on other sites

I've not worked with the imagecreate functions enough to be able to offer much more than I already have. Surely someone else has done this though; I see others here with dynamic avatars/signature images, etc.

Link to comment
https://forums.phpfreaks.com/topic/240065-imagecreate-failing/#findComment-1233414
Share on other sites

mod_rewrite?

 

Alright, I think we're onto the right track.  I've spent the last hour reading into mod_rewrite and think I have a decent grasp.  Not getting it done however.

 

With the img2.php script sitting in that /kat folder, my .htaccess in the root folder looks like this:

RewriteEngine on
RewriteRule ^/kat/img\.png$ /kat/img2.php

 

I got some 404s, so I also tried this:

RewriteEngine on
RewriteRule ^/kat/img2\.php$ /kat/img2.png [PT]

 

Still nothing. Anybody got a clue?

Link to comment
https://forums.phpfreaks.com/topic/240065-imagecreate-failing/#findComment-1233906
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.