$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
2
 /**
  * Internal
  *
  * Applies options before save or output
  *
  * @param \Gmagick $image
  * @param array    $options
  * @param string   $path
  *
  * @throws InvalidArgumentException
  */
 private function applyImageOptions(\Gmagick $image, array $options, $path)
 {
     if (isset($options['format'])) {
         $format = $options['format'];
     } elseif ('' !== ($extension = pathinfo($path, \PATHINFO_EXTENSION))) {
         $format = $extension;
     } else {
         $format = pathinfo($image->getImageFilename(), \PATHINFO_EXTENSION);
     }
     $format = strtolower($format);
     $options = $this->updateSaveOptions($options);
     if (isset($options['jpeg_quality']) && in_array($format, array('jpeg', 'jpg', 'pjpeg'))) {
         $image->setCompressionQuality($options['jpeg_quality']);
     }
     if ((isset($options['png_compression_level']) || isset($options['png_compression_filter'])) && $format === 'png') {
         // first digit: compression level (default: 7)
         if (isset($options['png_compression_level'])) {
             if ($options['png_compression_level'] < 0 || $options['png_compression_level'] > 9) {
                 throw new InvalidArgumentException('png_compression_level option should be an integer from 0 to 9');
             }
             $compression = $options['png_compression_level'] * 10;
         } else {
             $compression = 70;
         }
         // second digit: compression filter (default: 5)
         if (isset($options['png_compression_filter'])) {
             if ($options['png_compression_filter'] < 0 || $options['png_compression_filter'] > 9) {
                 throw new InvalidArgumentException('png_compression_filter option should be an integer from 0 to 9');
             }
             $compression += $options['png_compression_filter'];
         } else {
             $compression += 5;
         }
         $image->setCompressionQuality($compression);
     }
     if (isset($options['resolution-units']) && isset($options['resolution-x']) && isset($options['resolution-y'])) {
         if ($options['resolution-units'] == ImageInterface::RESOLUTION_PIXELSPERCENTIMETER) {
             $image->setimageunits(\Gmagick::RESOLUTION_PIXELSPERCENTIMETER);
         } elseif ($options['resolution-units'] == ImageInterface::RESOLUTION_PIXELSPERINCH) {
             $image->setimageunits(\Gmagick::RESOLUTION_PIXELSPERINCH);
         } else {
             throw new InvalidArgumentException('Unsupported image unit format');
         }
         $image->setimageresolution($options['resolution-x'], $options['resolution-y']);
     }
 }
示例#3
0
 /**
  * Internal
  *
  * Applies options before save or output
  *
  * @param \Gmagick $image
  * @param array    $options
  */
 private function applyImageOptions(\Gmagick $image, array $options)
 {
     if (isset($options['quality'])) {
         $image->setCompressionQuality($options['quality']);
     }
     if (isset($options['resolution-units']) && isset($options['resolution-x']) && isset($options['resolution-y'])) {
         if ($options['resolution-units'] == ImageInterface::RESOLUTION_PIXELSPERCENTIMETER) {
             $image->setimageunits(\Gmagick::RESOLUTION_PIXELSPERCENTIMETER);
         } elseif ($options['resolution-units'] == ImageInterface::RESOLUTION_PIXELSPERINCH) {
             $image->setimageunits(\Gmagick::RESOLUTION_PIXELSPERINCH);
         } else {
             throw new RuntimeException('Unsupported image unit format');
         }
         $image->setimageresolution($options['resolution-x'], $options['resolution-y']);
     }
 }
示例#4
0
 protected function set_quality($quality)
 {
     $this->image->setCompressionQuality($quality);
 }