This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2011-06-15 13:10:37

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

PHP Code for Forums Image Broken?

As most of you will have realized (I got many many 'complaints' recently), the image I used in my sig for the post count has been broken for a while. It's not that the link points to a nonexistent location: the PHP code that creates it is just not working.

Here's the code (which worked until a while ago):

Code:

<?php
 
// find posts...
// line 1224
 
 
// start making image
//creates a image handle
 
$file_name= 'http://scratch.mit.edu/forums/viewtopic.php?id=34152&p=1';
 
$scratchpage = file_get_contents("http://scratch.mit.edu/forums/viewtopic.php?id=34152&p=1");
 
$start = stripos($scratchpage,'<dd><a href="search.php?action=show_user&user_id=53856">Posts</a>: ');
$end = stripos($scratchpage,'</dd>',$start);
 
$posts = strip_tags(substr($scratchpage,$start + 67,$end - $start - 20));
 
// start
$img = imagecreatefrompng ( "bg.png" );
 
//choose a bg color, u can play with the rgb values
$background = imagecolorallocate( $img,232, 0, 135 );
 
//chooses the text color
$text_colour = imagecolorallocate( $img, 146, 208, 80 );
$colour2 = imagecolorallocate( $img, 0, 102, 0 );
 
//sets the thickness/bolness of the line
imagesetthickness ( $img, 3 );
 
//draws a line  params are (imgres,x1,y1,x2,y2,color)
imageline( $img, 20, 130, 165, 130, $text_colour );
 
//pulls the value passed in the URL
$text = 'Posts';
 
// place the font file in the same dir level as the php file
$font = 'font.ttf';
 
//this function sets the font size, places to the co-ords
imagettftext($img, 12, 0, 6, 15, $colour2, $font, $text);
//places another text with smaller size
imagettftext($img, 13, 0, 15, 35, $text_colour, $font, $posts);
 
//alerts the browser abt the type of content i.e. png image
header( 'Content-type: image/png' );
//now creates the image
imagepng( $img );
 
//destroys used resources
imagecolordeallocate( $text_color );
imagecolordeallocate( $background );
imagedestroy( $img );
?>

To all PHP coders, is there maybe a PHP version update of which I'm not aware of that obsoleted the above code? Or is it just my server, and I should maybe move the image to a different one?

I would appreciate some help. Thanks,
LS97

Oh, and I put this in AT because it is somewhat related to Scratch (it's about my sig) and it's obviously advanced.

Offline

 

#2 2011-06-15 13:38:00

TheSuccessor
Scratcher
Registered: 2010-04-23
Posts: 1000+

Re: PHP Code for Forums Image Broken?

Comment out the line "header( 'Content-type: image/png' );" temporarily and see if there are any PHP errors in the output.


/* No comment */

Offline

 

#3 2011-06-15 14:07:42

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: PHP Code for Forums Image Broken?

It's on line 1222 according to my source.

Offline

 

#4 2011-06-15 15:18:44

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: PHP Code for Forums Image Broken?

scimonster wrote:

It's on line 1222 according to my source.

The only thing I saw with 1222 lines was notepad decompiled into assembly code. What do you mean by 1222?

Offline

 

#5 2011-06-15 15:31:13

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: PHP Code for Forums Image Broken?

LS97 wrote:

scimonster wrote:

It's on line 1222 according to my source.

The only thing I saw with 1222 lines was notepad decompiled into assembly code. What do you mean by 1222?

Too big to post whole code, but in Firefox, it shows that on line 1222 of the source.

Offline

 

#6 2011-06-15 15:33:30

ProgrammingFreak
Scratcher
Registered: 2010-09-04
Posts: 1000+

Re: PHP Code for Forums Image Broken?

scimonster wrote:

LS97 wrote:

scimonster wrote:

It's on line 1222 according to my source.

The only thing I saw with 1222 lines was notepad decompiled into assembly code. What do you mean by 1222?

Too big to post whole code, but in Firefox, it shows that on line 1222 of the source.

Hmm..

Offline

 

#7 2011-06-15 16:04:13

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: PHP Code for Forums Image Broken?

Of course, 000webhost had to have a problem with its servers now...

Offline

 

#8 2011-06-16 15:59:06

TheSuccessor
Scratcher
Registered: 2010-04-23
Posts: 1000+

Re: PHP Code for Forums Image Broken?

Firefox wrote:

The image “http://mod-share.webuda.com/imgs/posts/image.php” cannot be displayed, because it contains errors.

See my post.


/* No comment */

Offline

 

#9 2011-06-17 02:57:01

TRocket
Scratcher
Registered: 2009-08-18
Posts: 1000+

Re: PHP Code for Forums Image Broken?

Could not find/open font in <b>/home/a2956315/public_html/imgs/posts/image.php</b> on line <b>42</b><br />

this line is the problem:

Code:

// place the font file in the same dir level as the php file
$font = 'font.ttf';

the font "font.ttf" is causing the error

Last edited by TRocket (2011-06-17 03:00:57)


http://i.imgur.com/1QqnHxQ.png

Offline

 

#10 2011-06-17 11:27:35

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: PHP Code for Forums Image Broken?

ok, thanks! i think PHP now changed the file not found to a fatal error...

Offline

 

#11 2011-06-17 11:41:36

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: PHP Code for Forums Image Broken?

And here we go, I got it working!

I used realpath('font.ttf') since I found out that ImageTTFText() only works with full paths.

http://bit.ly/jlyRCp

Offline

 

#12 2011-06-17 12:33:54

Wolfie1996
Retired Community Moderator
Registered: 2009-07-08
Posts: 1000+

Re: PHP Code for Forums Image Broken?

Closed by request of topic owner  smile


"...Jargon - the practice of never calling a spade a spade, when you might instead call it a manual earth-restructing implement..." - Bill Bryson, Mother Tongue

Offline

 

Board footer