diff --git src/wp-includes/class-wp-image-editor-imagick.php src/wp-includes/class-wp-image-editor-imagick.php
index a14fa40..fb49ef7 100644
|
|
class WP_Image_Editor_Imagick extends WP_Image_Editor { |
23 | 23 | */ |
24 | 24 | protected $image; |
25 | 25 | |
| 26 | /** |
| 27 | * Whether this is an animated image. |
| 28 | * |
| 29 | * @access protected |
| 30 | * @var bool |
| 31 | */ |
| 32 | protected $animated = false; |
| 33 | |
26 | 34 | public function __destruct() { |
27 | 35 | if ( $this->image instanceof Imagick ) { |
28 | 36 | // we don't need the original in memory anymore |
… |
… |
class WP_Image_Editor_Imagick extends WP_Image_Editor { |
63 | 71 | 'getimageblob', |
64 | 72 | 'getimagegeometry', |
65 | 73 | 'getimageformat', |
| 74 | 'getimageiterations', |
66 | 75 | 'setimageformat', |
67 | 76 | 'setimagecompression', |
68 | 77 | 'setimagecompressionquality', |
… |
… |
class WP_Image_Editor_Imagick extends WP_Image_Editor { |
139 | 148 | if ( ! $this->image->valid() ) |
140 | 149 | return new WP_Error( 'invalid_image', __('File is not an image.'), $this->file); |
141 | 150 | |
| 151 | // We need to check to see if image is animated before we set the index, or else it returns false. |
| 152 | // For animation to be supported, also getImageBlob, writeImages, coalesceImages and optimizeImageLayers are required. |
| 153 | // While coalesceImages seems to be supported far back, optimizeImageLayers is not. |
| 154 | $this->animated = $this->image->getImageIterations(); |
| 155 | |
142 | 156 | // Select the first frame to handle animated images properly |
143 | 157 | if ( is_callable( array( $this->image, 'setIteratorIndex' ) ) ) |
144 | 158 | $this->image->setIteratorIndex(0); |
145 | 159 | |
146 | 160 | $this->mime_type = $this->get_mime_type( $this->image->getImageFormat() ); |
| 161 | |
147 | 162 | } |
148 | 163 | catch ( Exception $e ) { |
149 | 164 | return new WP_Error( 'invalid_image', $e->getMessage(), $this->file ); |
… |
… |
class WP_Image_Editor_Imagick extends WP_Image_Editor { |
250 | 265 | } |
251 | 266 | |
252 | 267 | try { |
253 | | /** |
254 | | * @TODO: Thumbnail is more efficient, given a newer version of Imagemagick. |
255 | | * $this->image->thumbnailImage( $dst_w, $dst_h ); |
256 | | */ |
257 | | $this->image->scaleImage( $dst_w, $dst_h ); |
| 268 | if ( $this->animated ) { |
| 269 | $this->image->coalesceImages(); |
| 270 | } |
| 271 | |
| 272 | foreach ($this->image as $frame) { |
| 273 | /** |
| 274 | * @TODO: Thumbnail is more efficient, given a newer version of Imagemagick. |
| 275 | * $this->image->thumbnailImage( $dst_w, $dst_h ); |
| 276 | */ |
| 277 | $frame->scaleImage( $dst_w, $dst_h ); |
| 278 | } |
| 279 | |
| 280 | # $this->deconstructImages(); or $this->optimizeImageLayers(); |
| 281 | if ( $this->animated ) { |
| 282 | $this->image->optimizeImageLayers(); |
| 283 | } |
258 | 284 | } |
259 | 285 | catch ( Exception $e ) { |
260 | 286 | return new WP_Error( 'image_resize_error', $e->getMessage() ); |
… |
… |
class WP_Image_Editor_Imagick extends WP_Image_Editor { |
356 | 382 | } |
357 | 383 | |
358 | 384 | try { |
359 | | $this->image->cropImage( $src_w, $src_h, $src_x, $src_y ); |
360 | | $this->image->setImagePage( $src_w, $src_h, 0, 0); |
| 385 | if ( $this->animated ) { |
| 386 | $this->image->coalesceImages(); |
| 387 | } |
| 388 | |
| 389 | foreach ($this->image as $frame) { |
| 390 | $frame->cropImage( $src_w, $src_h, $src_x, $src_y ); |
| 391 | $frame->setImagePage( $src_w, $src_h, 0, 0); |
361 | 392 | |
362 | | if ( $dst_w || $dst_h ) { |
363 | | // If destination width/height isn't specified, use same as |
364 | | // width/height from source. |
365 | | if ( ! $dst_w ) |
| 393 | if ( $dst_w || $dst_h ) { |
| 394 | // If destination width/height isn't specified, use same as |
| 395 | // width/height from source. |
| 396 | if ( ! $dst_w ) |
366 | 397 | $dst_w = $src_w; |
367 | | if ( ! $dst_h ) |
368 | | $dst_h = $src_h; |
| 398 | if ( ! $dst_h ) |
| 399 | $dst_h = $src_h; |
369 | 400 | |
370 | | $this->image->scaleImage( $dst_w, $dst_h ); |
371 | | return $this->update_size(); |
| 401 | $frame->scaleImage( $dst_w, $dst_h ); |
| 402 | } |
| 403 | } |
| 404 | |
| 405 | if ( $this->animated ) { |
| 406 | $this->image->optimizeImageLayers(); |
372 | 407 | } |
373 | 408 | } |
374 | 409 | catch ( Exception $e ) { |
… |
… |
class WP_Image_Editor_Imagick extends WP_Image_Editor { |
392 | 427 | * (GD rotates counter-clockwise) |
393 | 428 | */ |
394 | 429 | try { |
395 | | $this->image->rotateImage( new ImagickPixel('none'), 360-$angle ); |
| 430 | if ( $this->animated ) { |
| 431 | $this->image->coalesceImages(); |
| 432 | } |
| 433 | |
| 434 | foreach ($this->image as $frame) { |
| 435 | $frame->rotateImage( new ImagickPixel('none'), 360-$angle ); |
| 436 | } |
| 437 | |
| 438 | if ( $this->animated ) { |
| 439 | $this->image->optimizeImageLayers(); |
| 440 | } |
396 | 441 | |
397 | 442 | // Since this changes the dimensions of the image, update the size. |
398 | 443 | $result = $this->update_size(); |
… |
… |
class WP_Image_Editor_Imagick extends WP_Image_Editor { |
419 | 464 | */ |
420 | 465 | public function flip( $horz, $vert ) { |
421 | 466 | try { |
422 | | if ( $horz ) |
423 | | $this->image->flipImage(); |
| 467 | if ( $this->animated ) { |
| 468 | $this->image->coalesceImages(); |
| 469 | } |
| 470 | |
| 471 | foreach ($this->image as $frame) { |
| 472 | if ( $horz ) |
| 473 | $frame->flipImage(); |
424 | 474 | |
425 | | if ( $vert ) |
426 | | $this->image->flopImage(); |
| 475 | if ( $vert ) |
| 476 | $frame->flopImage(); |
| 477 | } |
| 478 | |
| 479 | if ( $this->animated ) { |
| 480 | $this->image->optimizeImageLayers(); |
| 481 | } |
427 | 482 | } |
428 | 483 | catch ( Exception $e ) { |
429 | 484 | return new WP_Error( 'image_flip_error', $e->getMessage() ); |
… |
… |
class WP_Image_Editor_Imagick extends WP_Image_Editor { |
477 | 532 | $orig_format = $this->image->getImageFormat(); |
478 | 533 | |
479 | 534 | $this->image->setImageFormat( strtoupper( $this->get_extension( $mime_type ) ) ); |
480 | | $this->make_image( $filename, array( $image, 'writeImage' ), array( $filename ) ); |
| 535 | |
| 536 | if ( $this->animated ) { |
| 537 | $this->make_image( $filename, array( $image, 'writeImages' ), array( $filename, true ) ); |
| 538 | } else { |
| 539 | $this->make_image( $filename, array( $image, 'writeImage' ), array( $filename ) ); |
| 540 | } |
481 | 541 | |
482 | 542 | // Reset original Format |
483 | 543 | $this->image->setImageFormat( $orig_format ); |
… |
… |
class WP_Image_Editor_Imagick extends WP_Image_Editor { |
519 | 579 | |
520 | 580 | // Output stream of image content |
521 | 581 | header( "Content-Type: $mime_type" ); |
522 | | print $this->image->getImageBlob(); |
| 582 | |
| 583 | if ( $this->animated ) { |
| 584 | print $this->image->getImagesBlob(); |
| 585 | } else { |
| 586 | print $this->image->getImageBlob(); |
| 587 | } |
523 | 588 | |
524 | 589 | // Reset Image to original Format |
525 | 590 | $this->image->setImageFormat( $this->get_extension( $this->mime_type ) ); |