简体   繁体   中英

PHP Image editing (am I doing it wrong ?)


I need to resize and stitch togehter 7 images, for that I'm using ImageMagick but it's oughly heavy and takes a long time to perform. Is there any other lighter library I can use ? Or perhaps my code is to blame:

<?php
header('Content-type: image/jpeg');

$thumb = new Imagick();
$thumb->newImage(128*7,128, 'black');
$thumb->borderImage( 'purple', 1, 1 );

$images = new Imagick(glob('*.jpg'));

$counter =0;
foreach($images as $image) {

    // Providing 0 forces thumbnailImage to maintain aspect ratio
    $image->thumbnailImage(128,128, true);
    $thumb->compositeImage($image,Imagick::COMPOSITE_DEFAULT, (128*$counter)+(64-$image->getImageWidth()/2),64-$image->getImageHeight()/2);//echo $image;

    $counter++;
}
$thumb->setImageFormat('jpeg');
echo $thumb;    

?>

UPDATE:
As it is for an iPhone app I decided to do the resizing and stitching on the iPhone itself (and then upload the result to the server for future use).

I do not use imagick but use Imagemagick command line with php exec() and you can speed up jpg resizing using define as a "hint". I belive it only reads enough of the input image to create the output image.

Anyway there was a post on the Imagemagick forum a couple of weeks ago about speeding up jpg resizing with Imagick and the answer was:

$image = new Imagick();
$image->setOption('jpeg:size', '800x532');
$image->readImage('origional.jpg');

I am not sure how this would work in your case and the original thread is: http://www.imagemagick.org/discourse-server/viewtopic.php?f=10&t=20586&hilit=speed

As I'm writing an iPhone app and my resources on the server are low I decided to do the "hard" work on the iphone's side.

Daniel

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM