WordPress.org

Make WordPress Core

Ticket #6821: class-wp-image.php.patch

File class-wp-image.php.patch, 2.8 KB (added by tomauger, 7 years ago)

INCOMPLETE - just a starting point for discussion around general high-level methods for library-independent image manipulation.

  • wp-includes/class-wp-image.php

     
     1<?php
     2/**
     3 * Description of wp-image
     4 *
     5 * @author Tom Auger, Zeitguys
     6 */
     7class WP_Image {
     8        static $image;
     9        static $image_library_adaptor;
     10
     11        /**
     12         * Create an instance of a WP_Image.
     13         * $args can contain:
     14         * 'file' - URI or path to file. Will load the file and attempt to divine format from extension
     15         * 'format' - supported image format for loading a file (eg: jpeg, png etc)
     16         * 'width' - if creating a new file, set the width to this
     17         * 'height' - if creating a new file, set the height to this
     18         *
     19         * @param array $args Arguments controlling the creation parameters of the new instance
     20         */
     21        function __construct( $args ){
     22
     23        }
     24
     25        public function load_from_file( $url_or_path, $format = null ){
     26
     27        }
     28
     29        public function write_to_file( $path, $format = 'png' ){
     30
     31        }
     32
     33        public function get_geometry(){
     34                return array (
     35                        'width' => $width,
     36                        'height' => $height,
     37                        'channels' => $channels,
     38                        'bit_depth' => $bit_depth,
     39                        'mime_type' => $mime_type
     40                );
     41        }
     42
     43        /**
     44         * Resizes the image, or optionally produces a new WP_Image instance with the resize transformation applied, leaving the original intact.
     45         *
     46         * @uses apply_filters( 'wp_image_antialiasing_level' ) - if $anti_aliasing is used, this is the level of antialiasing used
     47         *
     48         * @param number $width Optional. New width, expressed in pixels or percentage (use '50%' for percentage)
     49         * @param number $height Optional. New height, expressed in pixels or percentage. If neither width nor height are provided, will just exit silently and do nothing.
     50         * @param boolean $return_copy Optional. Default false. When set to true, the method will return a new WP_Image object with the transformation applied, leaving the original unchanged.
     51         * @param boolean $force_proportional Optional. Default false. When set to true, will ensure that the proportions of the image are preserved. This allows you to specify only a width or a height, and the other will be automatically calculated. If you provide both a width and a height, the value representing the least % change will be applied.
     52         * @param boolean $anti_aliasing Optional. Whether to apply anti-aliasing (if available within the library)
     53         *
     54         * return mixed
     55         */
     56        public function resize( $width = null, $height = null, $return_copy = false, $force_proportional = false, $anti_aliasing = true ){
     57                $new_image = $this;
     58
     59                if ( $return_copy ){
     60                        return $new_image;
     61                } else {
     62                        $this = $new_image; // will this work?
     63                }
     64        }
     65
     66        public function rotate ( ){
     67               
     68        }
     69
     70}