How to create and save an image from the specified url

Downloads:3057 Bookmark this code Bookmark and Share
Rank : 4.5/5
Rated by : 2 user(s)
Developer:Andrew R  |   13 submission(s)
Date Uploaded:November 01,2009
Level:Begginer
Size: 0 Bytes
Category:PHP -> Images/Graphics
Developer Says:

The code below creates and saves an image from the url specified. URL must return an image and should not be an html page. The __FILE__ is a PHP constant and returns the absoulte path of current file

<?
	/*
	* The code below creates and saves an image from the url specified. URL must return an image and should not be an html page. The __FILE__ is a PHP constant
	* and returns the absoulte path of current file
	*/
 
	$url="http://snapcasa.com/get.aspx?code=5348&size=l&url=http://www.yahoo.com";
	$contents=file_get_contents($url);
	$img=imagecreatefromstring($contents);
	$img_path=dirname(__FILE__)."/thumb.jpg"); 
	imagejpeg($img,$img_path);
 ?>


User Reviews
Minh
[22-Aug-2011]
#1

It works perfectly

Leave a Comment
Age (Required, will not be shown)
Name
Email (Required, will not be shown)
Website (Optional, starting with http://)
 
Rate this code
Poor   1 2 3 4 5   Outstanding
Are you human ?

Enter the code shown above