1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Saving images locally

Discussion in 'PHP' started by sarahk, Apr 19, 2006.

  1. #1
    I show thumbnails on one of my directories and give the required accreditation back to the source.

    I'm playing around with different generators though because thumbnails.org don't index enough of the web.

    I have no problems getting the images and saving them but when I try to view them I get text crap and not the image. If I download the image using FTP the image is as expected.

    You can see my effort so far at http://www.top100vbulletin.com/cron/getThumbs.php and I do a var_dump(gd_info()); at the bottom but everything seems to be in order.

    The relevant part of my script is ...

    function saveGif ($imgname, $id)
    {
    	$im = @imagecreatefromgif ($imgname); /* Attempt to open */
    	if (!$im) 
    	{ /* See if it failed */
    		$im = @imagecreatefrompng($imgname);
    		if (!$im)
    		{
    			$im = @imagecreatefromjpeg($imgname);
    			if (!$im)
    			{
    				$im = imagecreatetruecolor (150, 30); /* Create a blank image */
    				$bgc = imagecolorallocate ($im, 255, 255, 255);
    				$tc = imagecolorallocate ($im, 0, 0, 0);
    				imagefilledrectangle ($im, 0, 0, 150, 30, $bgc);
    				/* Output an errmsg */
    				imagestring ($im, 1, 5, 5, "Error loading $imgname", $tc);
    			}
    		}
    	}
    	
    	imagegif($im, '../images/thumbs/t'.$id.'.gif');
    	imagejpeg($im, '../images/thumbs/t'.$id.'.jpg');
    	imagepng($im, '../images/thumbs/t'.$id.'.png');
    }//saveGif
    PHP:
    Can anyone see where I'm going wrong?
     
    sarahk, Apr 19, 2006 IP
    Will.Spencer likes this.
  2. digitalpoint

    digitalpoint Overlord of no one Staff

    Messages:
    38,333
    Likes Received:
    2,613
    Best Answers:
    462
    Trophy Points:
    710
    Digital Goods:
    29
    #2
    You setting the content type with the header() function? That might be all you are missing.

    For example for a PNG:

    header("Content-type: image/png");
    PHP:
     
    digitalpoint, Apr 19, 2006 IP
  3. sarahk

    sarahk iTamer Staff

    Messages:
    28,500
    Likes Received:
    4,460
    Best Answers:
    123
    Trophy Points:
    665
    #3
    Thanks Shawn, however that would make sense if I was outputting the image - but I'm saving it to a file and then using standard html <img> to call the image back up again.

    Header() will impact on the output of the actual script which is standard html.
     
    sarahk, Apr 19, 2006 IP
  4. digitalpoint

    digitalpoint Overlord of no one Staff

    Messages:
    38,333
    Likes Received:
    2,613
    Best Answers:
    462
    Trophy Points:
    710
    Digital Goods:
    29
    #4
    Oops... that's what I get for skimming. :)

    Try taking off the "@" from the imagecreate functions... maybe it's throwing an error or something that you are suppressing...
     
    digitalpoint, Apr 19, 2006 IP
  5. dataman

    dataman Peon

    Messages:
    94
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #5
    header returns 403 permission denied, check your folder (/images/thumbs/)permissions, it has to be a permissions problem!

    dm!
     
    dataman, Apr 19, 2006 IP
    sarahk likes this.
  6. digitalpoint

    digitalpoint Overlord of no one Staff

    Messages:
    38,333
    Likes Received:
    2,613
    Best Answers:
    462
    Trophy Points:
    710
    Digital Goods:
    29
    #6
    A 403 is a HTTP error code though. Makes me think that your http request to GET the image is failing and is being forbidden by the server you are getting it from. If that's the case your script is probably otherwise working fine. It's saving what it gets (an http 403 forbidden message instead of an actual image).
     
    digitalpoint, Apr 19, 2006 IP
  7. sarahk

    sarahk iTamer Staff

    Messages:
    28,500
    Likes Received:
    4,460
    Best Answers:
    123
    Trophy Points:
    665
    #7
    Blast, had the folder permissions wrong. Not quite sure how that worked given that the images were being written and read was on for all but 775 made all the difference!

    I've just discovered ya-right through another thread and that site seems to deliver the best result.

    http://www.top100vbulletin.com/cron/getThumbs.php?method=4

    It's interesting to see how a slow server impacts on the thumbnail production.

    Dataman - sent you a PM. Would love to have you onboard in the directory.
     
    sarahk, Apr 19, 2006 IP
  8. dataman

    dataman Peon

    Messages:
    94
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Capture it will return 1X1 transparent gif image if the site (times out, does not reply, invalid url, or is not found in a round robbin DNS lookup), Images by default are cached for 7 days! images are sized 120X90. But like I said, if you setup an account you can change all of this. Plus you can upload a file filled with urls and Capture It will process all of them and then email them to you, it has all kinds of options!

    dm!
     
    dataman, Apr 19, 2006 IP
  9. hansi

    hansi Peon

    Messages:
    129
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Looks nice now, good work sarahk
     
    hansi, Apr 19, 2006 IP