Ejemplo n.º 1
0
 /**
  * Whether the current environment is configured with required methods.
  *
  * @since 1.0.0
  *
  * @param  array $args
  * @return bool
  */
 public static function test($args = array())
 {
     if (!parent::test($args)) {
         return false;
     }
     return true;
 }
 /**
  * Crops Image.
  *
  * @since 3.5.0
  * @access public
  *
  * @param string|int $src The source file or Attachment ID.
  * @param int $src_x The start x position to crop from.
  * @param int $src_y The start y position to crop from.
  * @param int $src_w The width to crop.
  * @param int $src_h The height to crop.
  * @param int $dst_w Optional. The destination width.
  * @param int $dst_h Optional. The destination height.
  * @param boolean $src_abs Optional. If the source crop points are absolute.
  * @return boolean|WP_Error
  */
 public function crop($src_x, $src_y, $src_w, $src_h, $dst_w = null, $dst_h = null, $src_abs = false)
 {
     $ar = $src_w / $src_h;
     $dst_ar = $dst_w / $dst_h;
     if (isset($_GET['pte-fit-crop-color']) && abs($ar - $dst_ar) > 0.01) {
         PteLogger::debug(sprintf("AR: '%f'\tOAR: '%f'", $ar, $dst_ar));
         // Crop the image to the correct aspect ratio...
         if ($dst_ar > $ar) {
             // constrain to the dst_h
             $tmp_dst_h = $dst_h;
             $tmp_dst_w = $dst_h * $ar;
             $tmp_dst_y = 0;
             $tmp_dst_x = $dst_w / 2 - $tmp_dst_w / 2;
         } else {
             $tmp_dst_w = $dst_w;
             $tmp_dst_h = $dst_w / $ar;
             $tmp_dst_x = 0;
             $tmp_dst_y = $dst_h / 2 - $tmp_dst_h / 2;
         }
         // copy $this->image unto a new image with the right width/height.
         $img = wp_imagecreatetruecolor($dst_w, $dst_h);
         if (function_exists('imageantialias')) {
             imageantialias($img, true);
         }
         if (preg_match("/^#[a-fA-F0-9]{6}\$/", $_GET['pte-fit-crop-color'])) {
             $c = self::getRgbFromHex($_GET['pte-fit-crop-color']);
             $color = imagecolorallocate($img, $c[0], $c[1], $c[2]);
         } else {
             PteLogger::debug("setting transparent/white");
             //$color = imagecolorallocate( $img, 100, 100, 100 );
             $color = imagecolorallocatealpha($img, 255, 255, 255, 127);
         }
         imagefilledrectangle($img, 0, 0, $dst_w, $dst_h, $color);
         imagecopyresampled($img, $this->image, $tmp_dst_x, $tmp_dst_y, $src_x, $src_y, $tmp_dst_w, $tmp_dst_h, $src_w, $src_h);
         if (is_resource($img)) {
             imagedestroy($this->image);
             $this->image = $img;
             $this->update_size();
             return true;
         }
         return new WP_Error('image_crop_error', __('Image crop failed.'), $this->file);
     }
     return parent::crop($src_x, $src_y, $src_w, $src_h, $dst_w, $dst_h, $src_abs);
 }
Ejemplo n.º 3
0
 public function multi_resize($sizes)
 {
     $is_animated_gif = GifFrameExtractor::isAnimatedGif($this->file);
     if (!$is_animated_gif) {
         return parent::multi_resize($sizes);
     }
     $metadata = array();
     $orig_size = $this->size;
     foreach ($sizes as $size => $size_data) {
         $image = $this->_resize_animated_gif($size_data['width'], $size_data['height'], $size_data['crop']);
         if (!is_wp_error($image)) {
             $resized = $this->_save_animated_gif($image);
             unset($image);
             if (!is_wp_error($resized) && $resized) {
                 unset($resized['path']);
                 $metadata[$size] = $resized;
             }
         }
         $this->size = $orig_size;
     }
     return $metadata;
 }
Ejemplo n.º 4
0
 /**
  * Test flipping an image
  */
 public function test_flip()
 {
     $file = DIR_TESTDATA . '/images/gradient-square.jpg';
     $gd_image_editor = new WP_Image_Editor_GD($file);
     $gd_image_editor->load();
     $property = new ReflectionProperty($gd_image_editor, 'image');
     $property->setAccessible(true);
     $color_top_left = imagecolorat($property->getValue($gd_image_editor), 0, 0);
     $gd_image_editor->flip(true, false);
     $this->assertEquals($color_top_left, imagecolorat($property->getValue($gd_image_editor), 0, 99));
 }
 public function update_size($width = null, $height = null)
 {
     return parent::update_size($width, $height);
 }
 /**
  * Test WP_Image_Editor_GD handles extension-less images
  * @ticket 39195
  */
 public function test_image_non_existent_extension()
 {
     $image_editor = new WP_Image_Editor_GD(DIR_TESTDATA . '/images/test-image-no-extension');
     $result = $image_editor->load();
     $this->assertTrue($result);
 }