rotate example


    public function reorient(bool $silent = false)
    {
        $orientation = $this->getEXIF('Orientation', $silent);

        switch ($orientation) {
            case 2:
                return $this->flip('horizontal');

            case 3:
                return $this->rotate(180);

            case 4:
                return $this->rotate(180)->flip('horizontal');

            case 5:
                return $this->rotate(90)->flip('horizontal');

            case 6:
                return $this->rotate(90);

            case 7:
                

        $image = apply_filters_deprecated( 'image_edit_before_change', array( $image$changes ), '3.5.0', 'wp_image_editor_before_change' );
    }

    foreach ( $changes as $operation ) {
        switch ( $operation->type ) {
            case 'rotate':
                if ( 0 != $operation->angle ) {
                    if ( $image instanceof WP_Image_Editor ) {
                        $image->rotate( $operation->angle );
                    } else {
                        $image = _rotate_image_resource( $image$operation->angle );
                    }
                }
                break;
            case 'flip':
                if ( 0 != $operation->axis ) {
                    if ( $image instanceof WP_Image_Editor ) {
                        $image->flip( ( $operation->axis & 1 ) != 0, ( $operation->axis & 2 ) != 0 );
                    } else {
                        $image = _flip_image_resource( $image( $operation->axis & 1 ) != 0, ( $operation->axis & 2 ) != 0 );
                    }

        }

        foreach ( $modifiers as $modifier ) {
            $args = $modifier['args'];
            switch ( $modifier['type'] ) {
                case 'rotate':
                    // Rotation direction: clockwise vs. counter clockwise.                     $rotate = 0 - $args['angle'];

                    if ( 0 !== $rotate ) {
                        $result = $image_editor->rotate( $rotate );

                        if ( is_wp_error( $result ) ) {
                            return new WP_Error(
                                'rest_image_rotation_failed',
                                __( 'Unable to rotate this image.' ),
                                array( 'status' => 500 )
                            );
                        }
                    }

                    break;

                
$j4  = $x4  = self::load_4(self::substr($k, 12, 4));
        $j6  = $x6  = self::load_4(self::substr($in, 0, 4));
        $j7  = $x7  = self::load_4(self::substr($in, 4, 4));
        $j8  = $x8  = self::load_4(self::substr($in, 8, 4));
        $j9  = $x9  = self::load_4(self::substr($in, 12, 4));
        $j11 = $x11 = self::load_4(self::substr($k, 16, 4));
        $j12 = $x12 = self::load_4(self::substr($k, 20, 4));
        $j13 = $x13 = self::load_4(self::substr($k, 24, 4));
        $j14 = $x14 = self::load_4(self::substr($k, 28, 4));

        for ($i = self::ROUNDS; $i > 0; $i -= 2) {
            $x4 ^= self::rotate($x0 + $x12, 7);
            $x8 ^= self::rotate($x4 + $x0, 9);
            $x12 ^= self::rotate($x8 + $x4, 13);
            $x0 ^= self::rotate($x12 + $x8, 18);

            $x9 ^= self::rotate($x5 + $x1, 7);
            $x13 ^= self::rotate($x9 + $x5, 9);
            $x1 ^= self::rotate($x13 + $x9, 13);
            $x5 ^= self::rotate($x1 + $x13, 18);

            $x14 ^= self::rotate($x10 + $x6, 7);
            $x2 ^= self::rotate($x14 + $x10, 9);
            
$x4  = self::load_4(self::substr($k, 12, 4));
        $x11 = self::load_4(self::substr($k, 16, 4));
        $x12 = self::load_4(self::substr($k, 20, 4));
        $x13 = self::load_4(self::substr($k, 24, 4));
        $x14 = self::load_4(self::substr($k, 28, 4));
        $x6  = self::load_4(self::substr($in, 0, 4));
        $x7  = self::load_4(self::substr($in, 4, 4));
        $x8  = self::load_4(self::substr($in, 8, 4));
        $x9  = self::load_4(self::substr($in, 12, 4));

        for ($i = self::ROUNDS; $i > 0; $i -= 2) {
            $x4 ^= self::rotate($x0 + $x12, 7);
            $x8 ^= self::rotate($x4 + $x0, 9);
            $x12 ^= self::rotate($x8 + $x4, 13);
            $x0 ^= self::rotate($x12 + $x8, 18);
            $x9 ^= self::rotate($x5 + $x1, 7);
            $x13 ^= self::rotate($x9 + $x5, 9);
            $x1 ^= self::rotate($x13 + $x9, 13);
            $x5 ^= self::rotate($x1 + $x13, 18);
            $x14 ^= self::rotate($x10 + $x6, 7);
            $x2 ^= self::rotate($x14 + $x10, 9);
            $x6 ^= self::rotate($x2 + $x14, 13);
            $x10 ^= self::rotate($x6 + $x2, 18);
            

    public function reorient(bool $silent = false)
    {
        $orientation = $this->getEXIF('Orientation', $silent);

        switch ($orientation) {
            case 2:
                return $this->flip('horizontal');

            case 3:
                return $this->rotate(180);

            case 4:
                return $this->rotate(180)->flip('horizontal');

            case 5:
                return $this->rotate(270)->flip('horizontal');

            case 6:
                return $this->rotate(270);

            case 7:
                

                $result = $this->flip( true, true );
                break;
            case 4:
                // Flip vertically.                 $result = $this->flip( true, false );
                break;
            case 5:
                // Rotate 90 degrees counter-clockwise and flip vertically.                 $result = $this->rotate( 90 );

                if ( ! is_wp_error( $result ) ) {
                    $result = $this->flip( true, false );
                }

                break;
            case 6:
                // Rotate 90 degrees clockwise (270 counter-clockwise).                 $result = $this->rotate( 270 );
                break;
            case 7:
                
class RotateImageEffect extends ConfigurableImageEffectBase {

  /** * {@inheritdoc} */
  public function applyEffect(ImageInterface $image) {
    if (!empty($this->configuration['random'])) {
      $degrees = abs((float) $this->configuration['degrees']);
      $this->configuration['degrees'] = rand(-$degrees$degrees);
    }

    if (!$image->rotate($this->configuration['degrees']$this->configuration['bgcolor'])) {
      $this->logger->error('Image rotate failed using the %toolkit toolkit on %path (%mimetype, %dimensions)', ['%toolkit' => $image->getToolkitId(), '%path' => $image->getSource(), '%mimetype' => $image->getMimeType(), '%dimensions' => $image->getWidth() . 'x' . $image->getHeight()]);
      return FALSE;
    }
    return TRUE;
  }

  /** * {@inheritdoc} */
  public function transformDimensions(array &$dimensions$uri) {
    // If the rotate is not random and current dimensions are set,


  /** * Tests \Drupal\Core\Image\Image::rotate(). */
  public function testRotate() {
    $this->getTestImageForOperation('Rotate');
    $this->toolkitOperation->expects($this->once())
      ->method('execute')
      ->will($this->returnArgument(0));

    $ret = $this->image->rotate(90);
    $this->assertEquals(90, $ret['degrees']);
  }

}

  public function testRotateDimensions($width$height$angle$exp_width$exp_height) {
    $rect = new Rectangle($width$height);
    $rect->rotate($angle);
    $this->assertEquals($exp_width$rect->getBoundingWidth());
    $this->assertEquals($exp_height$rect->getBoundingHeight());
  }

  /** * Provides data for image dimension rotation tests. * * This dataset sample was generated by running on PHP 5.5 the function below * - first, for all integer rotation angles (-360 to 360) on a rectangle * 40x20; * - second, for 500 random float rotation angle in the range -360 to 360 on * a rectangle 40x20; * - third, on 1000 rectangles of random WxH rotated to a random float angle * in the range -360 to 360 * - fourth, on 2000 rectangles of random WxH rotated to a random integer * angle multiple of 30 degrees in the range -360 to 360 (which is the most * tricky case). * Using the GD toolkit operations gives us true data coming from the GD * library that can be used to match against the Rectangle class under test. * @code * protected function rotateResults($width, $height, $angle, &$new_width, &$new_height) { * $image = \Drupal::service('image.factory')->get(NULL, 'gd'); * $image->createNew($width, $height); * $old_res = $image->getToolkit()->getResource(); * $image->rotate($angle); * $new_width = $image->getWidth(); * $new_height = $image->getHeight(); * if (is_resource($old_res)) { * imagedestroy($old_res); * } * } * @endcode * * @return array[] * A simple array of simple arrays, each having the following elements: * - original image width * - original image height * - rotation angle in degrees * - expected image width after rotation * - expected image height after rotation * * @see testRotateDimensions() */

    protected static function quarterRound($a$b$c$d)
    {
        # a = PLUS(a,b); d = ROTATE(XOR(d,a),16);         /** @var int $a */
        $a = ($a + $b) & 0xffffffff;
        $d = self::rotate($d ^ $a, 16);

        # c = PLUS(c,d); b = ROTATE(XOR(b,c),12);         /** @var int $c */
        $c = ($c + $d) & 0xffffffff;
        $b = self::rotate($b ^ $c, 12);

        # a = PLUS(a,b); d = ROTATE(XOR(d,a), 8);         /** @var int $a */
        $a = ($a + $b) & 0xffffffff;
        $d = self::rotate($d ^ $a, 8);

        
Home | Imprint | This part of the site doesn't use cookies.