Page 1 of 1

thumbnail creator problems

Posted: Thu Aug 30, 2007 11:32 pm
by utinaeniduin
I have been looking for a simple bit of code that will allow me to use any image already uploaded and resize it down to a small thumbnail. I have found a lot, but this code seems to be as closest to what I want.

Code: Select all

// Get image info from variable
	$url = $_GET['url'];
	$img = getimagesize($url);//line 7
	
	// Checks if URL is image
	if ( $img[2] == 1 ) {
		$pic = imagecreatefromgif( $url ) or die();
	} elseif ( $img[2] == 2 ) {
		$pic = imagecreatefromjpeg( $url ) or die();
	} elseif ( $img[2] ==3 ) {
		$pic = imagecreatefrompng( $url ) or die();
	} else {exit();}
	
	
	// If an image is found and we can determine that it is an image
	if ($pic) {
		// Get width and height from the image
		$width = imagesx($pic);
		$height = imagesy($pic);
		$theight = 100;
		
		// Calculate the new width
		$twidth = ($theight * $width) / $height;
	
		// Create new image
		$thumb = @imagecreatetruecolor ( $twidth, $theight )
		or die ("Can't create Image!");
	
		// Resize the image into a thumb
		imagecopyresized($thumb, $pic, 0, 0, 0, 0,
		$twidth, $theight, $width, $height);
	
		// Change page type to a jpeg
		header ("Content-type: image/jpeg");
	
		// Create jpeg image from thumbnail
		imagejpeg($thumb,"",75);
	
	} else {exit();}
the only problem is that when I execute it I get these two errors:

Warning: getimagesize() [function.getimagesize]: URL file-access is disabled in the server configuration in /home/public_html/path/thumbnail.php on line 7

Warning: getimagesize(http://www.mysite.com/images/image.jpg) [function.getimagesize]: failed to open stream: no suitable wrapper could be found in /home/public_html/path/thumbnail.php on line 7

Posted: Fri Aug 31, 2007 2:27 am
by onion2k
PHP is configured to stop you accessing files via a URL. You can only access local files.

Posted: Fri Aug 31, 2007 9:46 am
by utinaeniduin
ooh ok. lucky for me I was just using that as an example. the way I was planning on using it is by linking to a php image fetcher called getdata.php. so the url that I am trying to get to work is http://www.mysite.com/pathto/thumbnail. ... a.php?id=3

but now I am getting this error:

Warning: getimagesize(getdata.php?id=3) [function.getimagesize]: failed to open stream: No such file or directory in /home/public_html/path/thumbnail.php on line 7.

I am able to fetch the original image by going to http://www.mysite.com/pathto/getdata.php?id=3

Posted: Sat Sep 01, 2007 1:14 pm
by utinaeniduin
does anyone know why this is happening?

Posted: Sat Sep 01, 2007 1:25 pm
by superdezign
Try using absolute paths.

Posted: Sat Sep 01, 2007 8:01 pm
by utinaeniduin
ok i figured it out that this script i have does not work when i use the getdata.php file (which fetches images from a db) as the url. this script did work when i tried using a picture in the same folder. does anyone have an idea of how i can get an image from a db resized without saving it as a new file?