0

here imagick works for image which are stored in server.. but i dont know how to work if i replace with remote url in $paths array

$background = new Imagick('back.jpg');
    $paths  = array(
        "img/1.jpg",
        "img/2.jpg",
        "img/3.jpg",
        "img/4.jpg",
    );

    $images = new Imagick($paths);
    foreach($images as $image){
      $image->thumbnailImage($width, NULL);
      $background->compositeImage($image, Imagick::COMPOSITE_OVER, $x ,$y );
    }
Rajesh Dante
  • 29
  • 2
  • 8
  • Get the image with file_get_contents or something similar, create an image resource from what you get and start working. Or you can download the image to a temporary directory, open it from there and work with that image resource. – clentfort Sep 20 '12 at 18:30

2 Answers2

6

Try using file_get_contents and file_put_contents to temporarily store the image on your local server:

<?php
$remote_image = file_get_contents("http://foo.com/remote_image.jpg");
file_put_contents("/tmp/remote_image.jpg", $remote_image);
$image = new Imagick("/tmp/remote_image.jpg");
?>
Daniel Li
  • 14,976
  • 6
  • 43
  • 60
2

I know it's old but for the record, here's a better way to do this without saving to disk:

$image_url = 'http://example.com/input.jpg';
$imageBlob = file_get_contents($image_url);
 
$imagick = new Imagick();
$imagick->readImageBlob($imageBlob); 

header("Content-Type: image/jpeg");
echo $imagick->getImageBlob(); //for animated gifs - getImagesBlob()
Miro
  • 8,402
  • 3
  • 34
  • 72