1

Is there any script that resizes an external image and outputs it ?

For example, i want to resize all external square images to 130X130.

Like this

http://mydomain.com/script/resize.php?url=http://otherdomain.com/image.png

EDIT: Facebook also is an example maybe https://s-external.ak.fbcdn.net/safe_image.php?d=AQCYX3NIE5gMyujT&url=http%3A%2F%2Fi2.ytimg.com%2Fvi%2FyoLeJNjIVZk%2Fhqdefault.jpg

any help appreciated.

Thanks

Utku Dalmaz
  • 9,780
  • 28
  • 90
  • 130
  • For a stock PHP installation, it makes absolutely no difference if the image to be resized is local or not. You do not even have to change the function that reads the image data (`file_get_contents`). Have you actually tried to do anything yourself? – Jon Mar 06 '12 at 10:48
  • i want to get the image data from my own server with resizing, not from an external address. Also, this is a Q&A platform as i know and i can ask anything i want, if you don't wanna answer please stay away and don't judge me if i make anything myself or not ! – Utku Dalmaz Mar 06 '12 at 10:53
  • Well, you can ask anything indeed but it wouldn't be a bad idea to follow the [advice on how to ask](http://stackoverflow.com/questions/how-to-ask). Also, it is as much my right to comment as it is yours to ask. – Jon Mar 06 '12 at 10:58
  • You can comment, of course. But try to be constructive pls... – Utku Dalmaz Mar 06 '12 at 10:59

3 Answers3

4
// Content type 
header('Content-Type: image/jpeg');

//get image from internet and save it into local disk
$url = 'http://www.google.com/images/srpr/logo3w.png';
$img = 'google.png';
file_put_contents($img, file_get_contents($url));


//get  current size and set new size
list($width, $height) = getimagesize($img);
$new_width = 130;
$new_height = 130;

// genarate resized image copy
$image_p = imagecreatetruecolor($new_width, $new_height);
$image = imagecreatefrompng($img);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);

// flush image to browser
imagejpeg($image_p, null, 100);
// save resised image to disk 
imagejpeg($image_p, "newimage.jpg",100);

Use this code only if you want to resize and save on your application otherwise above example is enough.

Nathan
  • 11,814
  • 11
  • 50
  • 93
Ullas Prabhakar
  • 3,546
  • 3
  • 28
  • 27
1

Take a look at this thread. You can write your own code to resize images or use TimThumb script.

Community
  • 1
  • 1
ronakg
  • 4,038
  • 21
  • 46
1

if you dont want to save them than you can just set the with and hight with html or css

<img height="130px" with="130px;" src="somesite.com/img.jpg"></img>
tgb
  • 91
  • 1
  • 7