Php generated images doesn't work with long url *SOLVED*

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
MrOpposite
Forum Newbie
Posts: 1
Joined: Sun Jun 14, 2009 6:01 pm

Php generated images doesn't work with long url *SOLVED*

Post by MrOpposite »

Hi there, I'm making myself a twitter-to-image script. Which I should be able to use in forum signatures etc. I created the image generating code. and it works like a charm, when I use this html:

Code: Select all

<img src="twittimg.php">
However, as soon as I'm trying it this way:

Code: Select all

<img src="http://imgtwitt.000space.com/images/twittimg.php">
I get a broken image icon. I've tried whith diffrent browsers (IE, FF, Chrome) it doesn't work.
I even made my host treat PNG files as PHP, and I still get get the same result.

Here is something to clarefy:

Code: Select all

 
<img src="http://imgtwitt.000space.com/images/twittimg.php"> //Doesn't Work
<img src="twittimg.php"> //work
<img src="http://imgtwitt.000space.com/images/twittimg.png"> //Doesn't Work
<img src="twittimg.png"> //work
This is very odd. and i wonder if it has anything to do whith the host, (000space.com) or the script.


Here is my php-script:

Code: Select all

 
<?php
header('Content-type: image/png');
$fp = fsockopen("twitter.com", 80, $errno, $errstr, 30);
if (!$fp) {
    $str = "$errstr ($errno)";
} else {
//    $out = "GET /statuses/user_timeline/". $_GET['rssid'] .".rss HTTP/1.1\r\n";
    $out = "GET /statuses/user_timeline/45608816.rss HTTP/1.1\r\n";
    $out .= "Host: twitter.com\r\n";
    $out .= "Connection: Close\r\n\r\n";
    fwrite($fp, $out);
    $str = "";
    while (!feof($fp)) {
        $str = $str . fgets($fp, 128);
    }
    fclose($fp);
    
}
 
$str = substr(stristr($str,"</ttl>"),6);
$str = str_replace(chr(ord($str)),"",$str);
 
$num = substr_count($str,"<title>");
for($i = 0; $i < $num; $i++)
{
    $pos1 = strpos($str,"<title>");
    $pos2 = strpos($str,"</title>")+8;
    $str1 = substr($str,0,$pos1);
    $str2 = substr($str,$pos2);
    $str  = $str1 . $str2;
}
 
$num = substr_count($str,"<link>");
for($i = 0; $i < $num; $i++)
{
    $pos1 = strpos($str,"<link>");
    $pos2 = strpos($str,"</link>")+7;
    $str1 = substr($str,0,$pos1);
    $str2 = substr($str,$pos2);
    $str  = $str1 . $str2;
}
 
 
$num = substr_count($str,"<pubDate>");
for($i = 0; $i < $num; $i++)
{
    $pos1 = strpos($str,"<pubDate>");
    $pos2 = strpos($str,"</pubDate>")+10;
    $str1 = substr($str,0,$pos1);
    $str2 = substr($str,$pos2);
    $str  = $str1 . $str2;
}
 
$num = substr_count($str,"<guid>");
for($i = 0; $i < $num; $i++)
{
    $pos1 = strpos($str,"<guid>");
    $pos2 = strpos($str,"</guid>")+7;
    $str1 = substr($str,0,$pos1);
    $str2 = substr($str,$pos2);
    $str  = $str1 . $str2;
}
 
$str = str_replace("<item>","",$str);
$str = str_replace("</item>","",$str);
$str = str_replace("</channel>","",$str);
$str = str_replace("</rss>","",$str);
$str = str_replace("</description>","",$str);
while(substr_count($str," <description>")>0)
{
    $str = substr_replace($str,"",stripos($str," <description>"),1);
}
//$str = str_replace("<description>",ord(127),$str);
$str = trim($str);
$str = htmAscii($str);
$str = wordwrap($str,78,"<description>",true);
$num = substr_count($str,"<description>");
$str = explode("<description>",$str);
 
//$im = imageCreate($_GET['width'], $_GET['height']);
$im = imageCreate(550, 150);
$bkgColor  = hex2int('FFFFFF');
$txtColor1 = hex2int('000000');
$txtColor2 = hex2int('FF00F0');
$font = 3;
$x = 2;
$y = 2;
$bkgC  = imageColorAllocate($im, $bkgColor['r'], $bkgColor['g'], $bkgColor['b']);
$col   = 1;
$txtC1 = imageColorAllocate($im, $txtColor1['r'], $txtColor1['g'], $txtColor1['b']);
$txtC2 = imageColorAllocate($im, $txtColor2['r'], $txtColor2['g'], $txtColor2['b']);
for($i = 0; $i < min(13,$num); $i++)
{
    if($col == 0)
    {
        imageString($im,$font,$x,$y+(($i-1)*11),$str[$i],$txtC1);
        if(strstr($str[min(min(13,$num),$i+1)],"MrOpposite: ") != false)
        {
            $col = 1;
        }
    }
    else
    {
        imageString($im,$font,$x,$y+(($i-1)*11),$str[$i],$txtC2);
        if(strstr($str[min(min(13,$num),$i+1)],"MrOpposite: ") != false)
        {
            $col = 0;
        }
    }
}
imagePNG ($im); 
imageDestroy ($im); 
 
function hex2int($hex) {
        return array( 'r' => hexdec(substr($hex, 0, 2)), // 1st pair of digits
                      'g' => hexdec(substr($hex, 2, 2)), // 2nd pair
                      'b' => hexdec(substr($hex, 4, 2))  // 3rd pair
                    );
}
 
function htmAscii($input)
{
    /*snipped out this code, i think the forum didn't like it... also, it was just a bunch of str_replace functions*/
    return $input;
}
 
?>
Also, this is my first post, so if I missed something, pleas tell me so I'll do better next time ^^

Oh yea, if you view the http://imgtwitt.000space.com/twittimg.php in the browser, the image pops upas it should, also my browser loads the image perfectly aswell...

edit:
added extra info

EDIT2:
I changed my web-host, and the images could be seen extarnally, and with long url's.
Post Reply