Greenguy's Board

Greenguy's Board (http://www.greenguysboard.com/board/index.php)
-   Programming & Scripting (http://www.greenguysboard.com/board/forumdisplay.php?f=15)
-   -   PHP - How to get dimension of hotlink protected image? (TGP) (http://www.greenguysboard.com/board/showthread.php?t=44498)

guschi2k 2007-12-18 11:15 PM

PHP - How to get dimension of hotlink protected image? (TGP)
 
Hey all :)

I'm trying to retrieve the dimensions/resolution of the fullsize images of TGP galleries. getimagesize() is of course not working with hotlink protected images, so I guess the only way is establishing a connetion with fsockopen() and sending false referrer information.

I tried that already and retrieving http status, last modified date, filesize etc is no problem ... but how would I go about the resolution?

I tried sending a "GET /image.jpg" already, but then my browser prompts me to download the file and choses myscript.php as the filename.

My head hurts already :-/ Maybe there's a rather simple solution? Writing the output of the GET request to a temp file on my webspace and doing a getimagesize() was what I thought about ... but it seems a little overcomplicated?
Also ... retrieving all pictures of the ~700-800 tgp gallery submission every day would be quite a waste of bandwidth :-/ and even worse ... when I run my linkbot to check all submitted galleries, this would be ... HOLY MOSES ... too many gigs to count :o


Thanks for aaaaaaaaalllll help |headbang|

tickler 2007-12-20 12:15 AM

Actually PHP can bypass hotlinking(If I remember right, from some TGP scripts)

PHP Code:

list($width$height$type$attr) = getimagesize("http://www.example.com/gifs/lo%20go.gif"); 


Also look at this code snippet from my thumbnailer routine:
PHP Code:

$wrkImage imagecreatefromjpeg($rawPicURL);

echo 
imagesx($wrkImage); // image width
echo imagesy($wrkImage); // image height 


guschi2k 2007-12-20 01:41 PM

Thanks for your answer :) Unfortunately it's not working for me, b/c as far as I know getimagesize() cannot bypass hotlinking |cry|

I tried it with this image:
http://www.shizzn.com/x/stuff/open/cimg3621.jpg - no hotlink protection
http://www.shizzn.com/x/stuff/prot/cimg3621.jpg - htaccess hotlink protection


I know tried it like that:
Code:

$target_host = "www.shizzn.com";
$target_path = "/x/stuff/prot/cimg3621.jpg";

#header("Content-Type: text/plain");
header("Content-Type: image/jpeg");
    $fp = fsockopen("$target_host", 80, $errno, $errstr, 5);
    if(!$fp){echo "$errstr ($errno)\n";}
    else
      {
      $out = "GET ". $target_path ." HTTP/1.1\r\n";
      $out .= "Host: ". $target_host ."\r\n";
      $out .= "Referer: http://". $target_host ."\r\n";
      $out .= "User-Agent: Blabla Browser Name(xyz)\r\n";
      $out .= "Keep-Alive: 200\r\n";
      $out .= "Connection: Close\r\n\r\n";

      fwrite($fp, $out);
      while (!feof($fp))
        {
        $status_request = fgets($fp, 500000);
        echo  $status_request;
        $file = fopen("temp_img.jpg","w+");
        fwrite($file,$status_request);
        fclose($file);
        }
      fclose($fp);
      }

but somehow it's just not working :( I'm no PHP expert, though I've been messing with it for years *lol ... if I could ... at least find out a way how to save the image to my server and then do a getimagesize() on the local file? |dizzy|

I just really s*ck! when it comes to file operations *lol If only a head request would also give info about the dimensions :( I'm using the head request to check the status (redirection, 404 etc) and the image size in bytes, which works perfectly fine :)

Greenguy 2007-12-20 02:29 PM

Forgive me for sounding naive, but isn't this one of the many reasons that anti-hotlinking protection is in place?

guschi2k 2007-12-20 03:32 PM

@greenie, No worries :)

I haven't used payed scripts for years, but as far as I remember they have anti-cheat mechanisms as well which are supposed to detect redirects, image size, dimensions and stuff. Brownie for example was one of the first - if not the first - scripts to retrieve image sizes and stuff.

So basically I'm just trying to find out how to do, what every good script should be able to do :)

It just has! to be possible to retrieve the dimensions of images, without downloading it entirely. After all, I want to make it a blazing fast script :D And right now it's sloooooooow ... but good! *lol


If only all submitters would just stick to the rules of TGPs/MGPs! *lol damn cheaters.


All times are GMT -4. The time now is 03:45 PM.

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
© Greenguy Marketing Inc