Created
September 6, 2012 18:24
-
-
Save kurtpayne/3659197 to your computer and use it in GitHub Desktop.
Abstract that thing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
abstract class WP_Image_Editor_Base { | |
protected $file = false; | |
protected $size = false; | |
protected $orig_type = false; | |
protected $quality = 90; | |
public function __construct( $filename ) { | |
xdebug_start_trace(); | |
$this->file = $filename; | |
} | |
public function __destruct() { | |
xdebug_stop_trace(); | |
} | |
public static function test() { | |
return false; | |
} | |
abstract protected function load(); | |
abstract public function resize( $max_w, $max_h, $crop = false ); | |
abstract public function multi_resize( $sizes ); | |
abstract public function crop( $src_x, $src_y, $src_w, $src_h, $dst_w = null, $dst_h = null, $src_abs = false ); | |
abstract public function rotate( $angle ); | |
abstract public function flip( $horz, $vert ); | |
abstract public function save( $destfilename = null ); | |
abstract public function stream(); | |
public function get_size() { | |
if ( ! $this->load() ) | |
return; | |
return $this->size; | |
} | |
protected function update_size( $width = false, $height = false ) { | |
$this->size = array( | |
'width' => $width, | |
'height' => $height | |
); | |
} | |
public function set_quality( $quality ) { | |
$this->quality = apply_filters( 'wp_editor_set_quality', $quality ); | |
} | |
public function generate_filename( $suffix = null, $dest_path = null ) { | |
if ( ! $this->load() ) | |
return; | |
// $suffix will be appended to the destination filename, just before the extension | |
$suffix = $this->get_suffix(); | |
$info = pathinfo( $this->file ); | |
$dir = $info['dirname']; | |
$ext = $info['extension']; | |
$name = wp_basename( $this->file, ".$ext" ); | |
if ( ! is_null( $dest_path ) && $_dest_path = realpath( $dest_path ) ) | |
$dir = $_dest_path; | |
return "{$dir}/{$name}-{$suffix}.{$ext}"; | |
} | |
public function get_suffix() { | |
if ( ! $this->get_size() ) | |
return; | |
if ( ! $this->load() ) | |
return; | |
return "{$this->size['width']}x{$this->size['height']}"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment