imagerotate example

// Create the image handle         $srcImg = $this->createImage();

        // Set the background color         // This won't work with transparent PNG files so we are         // going to have to figure out how to determine the color         // of the alpha channel in a future release.
        $white = imagecolorallocate($srcImg, 255, 255, 255);

        // Rotate it!         $destImg = imagerotate($srcImg$angle$white);

        // Kill the file handles         imagedestroy($srcImg);

        $this->resource = $destImg;

        return true;
    }

    /** * Flattens transparencies * * @return $this */
try {
                // use in-memory stream to read the EXIF-metadata,                 // to avoid downloading the image twice from a remote filesystem                 fwrite($stream$file);
                rewind($stream);

                $exif = @exif_read_data($stream);

                if ($exif !== false) {
                    if (!empty($exif['Orientation']) && $exif['Orientation'] === 8) {
                        $image = imagerotate($image, 90, 0);
                    } elseif (!empty($exif['Orientation']) && $exif['Orientation'] === 3) {
                        $image = imagerotate($image, 180, 0);
                    } elseif (!empty($exif['Orientation']) && $exif['Orientation'] === 6) {
                        $image = imagerotate($image, -90, 0);
                    }
                }
            } catch (\Exception) {
                // Ignore.             } finally {
                fclose($stream);
            }
        }

function _rotate_image_resource( $img$angle ) {
    _deprecated_function( __FUNCTION__, '3.5.0', 'WP_Image_Editor::rotate()' );

    if ( function_exists( 'imagerotate' ) ) {
        $rotated = imagerotate( $img$angle, 0 );

        if ( is_gd_image( $rotated ) ) {
            imagedestroy( $img );
            $img = $rotated;
        }
    }

    return $img;
}

/** * Flips an image resource. Internal use only. * * @since 2.9.0 * @deprecated 3.5.0 Use WP_Image_Editor::flip() * @see WP_Image_Editor::flip() * * @ignore * @param resource|GdImage $img Image resource or GdImage instance. * @param bool $horz Whether to flip horizontally. * @param bool $vert Whether to flip vertically. * @return resource|GdImage (maybe) flipped image resource or GdImage instance. */

  protected function execute(array $arguments) {
    // PHP installations using non-bundled GD do not have imagerotate.     if (!function_exists('imagerotate')) {
      $this->logger->notice('The image %file could not be rotated because the imagerotate() function is not available in this PHP installation.', ['%file' => $this->getToolkit()->getSource()]);
      return FALSE;
    }

    // Stores the original GD resource.     $original_res = $this->getToolkit()->getResource();

    if ($new_res = imagerotate($this->getToolkit()->getResource(), 360 - $arguments['degrees']$arguments['background_idx'])) {
      $this->getToolkit()->setResource($new_res);
      imagedestroy($original_res);

      // GIFs need to reassign the transparent color after performing the       // rotate, but only do so, if the image already had transparency of its       // own, or the rotate added a transparent background.       if (!empty($arguments['gif_transparent_color'])) {
        $transparent_idx = imagecolorexactalpha($this->getToolkit()->getResource()$arguments['gif_transparent_color']['red']$arguments['gif_transparent_color']['green']$arguments['gif_transparent_color']['blue']$arguments['gif_transparent_color']['alpha']);
        imagecolortransparent($this->getToolkit()->getResource()$transparent_idx);
      }

      

    public function rotate( $angle ) {
        if ( function_exists( 'imagerotate' ) ) {
            $transparency = imagecolorallocatealpha( $this->image, 255, 255, 255, 127 );
            $rotated      = imagerotate( $this->image, $angle$transparency );

            if ( is_gd_image( $rotated ) ) {
                imagealphablending( $rotated, true );
                imagesavealpha( $rotated, true );
                imagedestroy( $this->image );
                $this->image = $rotated;
                $this->update_size();
                return true;
            }
        }

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