$Image1->readImage($input_file);
    $timers['open'] += microtime(true) - $time_open_start;
    $time_get_info_start = microtime(true);
    $width = $Image1->getImageWidth();
    $height = $Image1->getImageHeight();
    $timers['get_info'] += microtime(true) - $time_get_info_start;
    $time_get_info_start = microtime(true);
    $new_width = ceil($width / TestSettings::DOWNSCALE_FACTOR);
    $new_height = ceil($height / TestSettings::DOWNSCALE_FACTOR);
    $timers['get_info'] += microtime(true) - $time_get_info_start;
    $time_scale_start = microtime(true);
    $Image1->scaleImage($new_width, $new_height);
    $timers['scale'] += microtime(true) - $time_scale_start;
    $time_rotate_start = microtime(true);
    $WhiteColor = new GmagickPixel('white');
    $Image1->rotateImage($WhiteColor, TestSettings::ROTATE_ANGLE);
    $timers['rotate'] += microtime(true) - $time_rotate_start;
    $time_new_start = microtime(true);
    $Image2 = new Gmagick();
    $Image2->newImage(TestSettings::OUTPUT_IMAGE_WIDTH, TestSettings::OUTPUT_IMAGE_HEIGHT, 'white');
    $timers['new'] += microtime(true) - $time_new_start;
    $time_paste_start = microtime(true);
    $Image2->compositeImage($Image1, 1, TestSettings::PASTE_X, TestSettings::PASTE_Y);
    $timers['paste'] += microtime(true) - $time_paste_start;
    $time_save_start = microtime(true);
    $Image2->setImageFormat('JPEG');
    $Image2->setCompressionQuality(TestSettings::OUTPUT_JPEG_QUALITY);
    file_put_contents($output_file, $Image2);
    $timers['save'] += microtime(true) - $time_save_start;
}
print_r(['gmagick' => $timers]);
Пример #2
0
 /**
  * Apply transformations on image
  *
  * @param string $source Source image
  * @param array  $params Transformations and parameters
  * @param string $store  Temporary store on disk
  *
  * @return string
  */
 public function transform($source, $params, $store = null)
 {
     try {
         $image = new \Gmagick();
         $image->readImage($source);
         if (isset($params['negate'])) {
             $this->canNegate();
         }
         if (isset($params['rotate'])) {
             $image->rotateImage('#000', $params['rotate']['angle']);
         }
         if (isset($params['crop'])) {
             $image->cropImage($params['crop']['width'], $params['crop']['height'], $params['crop']['x'], $params['crop']['y']);
         }
         if (isset($params['contrast'])) {
             $this->canContrast();
         }
         if (isset($params['brightness'])) {
             $value = (int) $params['brightness'];
             $brightness = null;
             if ($value <= 0) {
                 $brightness = $value + 100;
             } else {
                 $brightness = $value * 3 + 100;
             }
             $image->modulateImage($brightness, 100, 100);
         }
         $ret = null;
         if ($store !== null) {
             $ret = $image->writeImage($store);
         } else {
             $ret = $image->getImageBlob();
         }
         $image->destroy();
         return $ret;
     } catch (\GmagickException $e) {
         $image->destroy();
         throw new \RuntimeException($e->getMessage());
     }
 }