Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
Thread: PHP Image not working correctly
12-02-2008, 05:50 AM #1
PHP Image not working correctly
I recently switched hosts and my image thing stopped working.
I know my .htaccess works because I use /news/ and /profiles/ in it too. And yes I did CHMOD my directories to 777.
See all that nonsense?
here is the source
$id = $_GET[id];
$getx = mysql_query("SELECT * FROM `members` WHERE `id` = '$id'") or die(mysql_error()); //get all the
$user = mysql_fetch_array($getx);
// load the image from the file specified:
$im = imagecreatefrompng("images/compactstat.png");
// if there's an error, stop processing the page:
// define some colours to use with the image
$yellow = imagecolorallocate($im, 113, 113, 113);
$black = imagecolorallocate($im, 0, 0, 0);
// get the width and the height of the image
$width = imagesx($im);
$height = imagesy($im);
// draw a black rectangle across the bottom, say, 20 pixels of the image:
// now we want to write in the centre of the rectangle:
$font = 8; // store the int ID of the system font we're using in $font
$text = "$user[username]";
$text2 = "$user[cookies]"; // store the text we're going to write in $text
// calculate the left position of the text:
$leftTextPos = ( $width - imagefontwidth($font)*strlen($text) )/2;
$namecon3 = strlen($user[username]);
// finally, write the string:
imagestring($im, $font, 27, 22, $text, $yellow);
imagestring($im, $font, 70, 43, $text2, $yellow);
// output the image
// tell the browser what we're sending it
// tidy up
Nvm, I found out the problem myself.
It was this line that caused the problem:
Last edited by UrbanTwitch; 12-02-2008 at 06:38 AM.Formerly MysticScript
6+ years club
12-02-2008, 06:01 AM #2
- Join Date
- Sep 2002
- Saskatoon, Saskatchewan
- Thanked 2,662 Times in 2,631 Posts
The errors are being recorded to you're screen. Because of the errors, you can't send the proper headers to display you're image. What you see is an ascii representation of the binary data within the file. Pretty neat eh?
Anyway, you're imagestring is one thats killing it. This one:
The other one looks like its trying to write an image to an incorrect directory. Be more specific with it, try using an absolute path.
Once those are fixed, the image should display again. You're last host probably had output buffering enabled, which would still allow you to send you're proper headers after the errors occured.
Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)PHP Code:
header('HTTP/1.1 420 Enhance Your Calm');
Users who have thanked Fou-Lu for this post:
12-02-2008, 06:39 AM #3
haha yeah, thanks anyway Fou-Lu. What would the world do with out you? :P
6+ years club