grabs an image of another server and displays a resized version. you can
easily make and save thumbnails from remote images this way.
if you
use this to just display the image, make sure there is NO output before this
script, no blankspace, no nothing or you'll get a "headers already sent" error !
01<?php 02 03// make sure there is NO output before this script, no blankspace, no nothing 04// or you'll get a "headers already sent" error 05 06// the image from another site 07$off_site='http://fundisom.com/supersonnig/nyc/4.jpg'; 08 09// save thumbnail or display resized image. 10// leave blank to just show image 11// otherwise specify the path and name where the thumbnai is saved 12$savethumb=''; 13 14// read binary stream 15$fp=fopen($off_site,'rb')ordie('Unable to open file '.$off_site.' for reading'); 16$buf=''; 17while(!feof($fp)) 18{ 19$buf.=fgets($fp,4096); 20} 21fclose($fp); 22 23$data=$buf; 24 25//set new height 26$size=150; 27$src=imagecreatefromstring($data); 28$width=imagesx($src); 29$height=imagesy($src); 30$aspect_ratio=$height/$width; 31 32//start resizing 33if($height<=$size) 34{ 35$new_w=$width; 36$new_h=$height; 37}else{ 38$new_h=$size; 39$new_w=abs($new_h/$aspect_ratio); 40} 41 42$img=imagecreatetruecolor($new_w,$new_h); 43 44//output image 45imagecopyresampled($img,$src,0,0,0,0,$new_w,$new_h,$width,$height); 46 47// output header 48if(empty($savethumb))header('Content-Type: image/jpeg'); 49 50// determine image type and send it to the browser 51// or save to file if specified 52imagejpeg($img,$savethumb,90); 53imagedestroy($img); 54 55?>