| AND OR | string words | *

image handling

|

resize offsite image


grabs an image of another server and displays a resized version.
can save thumbnails from remote images.

! make sure there is NO output before this script, no blankspace, no nothing
or you'll get a "headers already sent" error !



full source of resize offsite image [ line 1 - 37 ] | download resize offsite image

1    <?php
2   // make sure there is NO output before this script, no blankspace, no nothing
3   // or you'll get a "headers already sent" error
4   // the image from another site
5   $off_site 'http://fundisom.com/supersonnig/nyc/4.jpg'
6   // read binary stream
7   $fp fopen ($off_site'rb') or die('Unable to open file '.$off_site.' for reading'); 
8   $buf '';
9   while (!feof ($fp)) 
10   { 
11      $buf .= fgets($fp4096); 
12   } 
13   // output header
14   header('Content-Type: image/jpeg');
15   $data $buf;
16   //set new height
17   $size 150;
18   $src imagecreatefromstring ($data);
19   $width imagesx($src);
20   $height imagesy($src);
21   $aspect_ratio $height/$width;
22   //start resizing
23   if ($height <= $size)
24   {
25       $new_w $width;
26       $new_h $height;
27   } else {
28       $new_h $size;
29       $new_w abs($new_h $aspect_ratio);
30   }
31   $img imagecreatetruecolor ($new_w,$new_h); 
32   //output image
33   imagecopyresampled ($img,$src,0,0,0,0,$new_w,$new_h,$width,$height); 
34   // determine image type and send it to the browser
35   imagejpeg($img''90); 
36   imagedestroy($img);
37   ?>



8 hits by 4 users in the last 30 minutes.