-
Notifications
You must be signed in to change notification settings - Fork 0
/
Image.php
65 lines (45 loc) · 1.47 KB
/
Image.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
/**
* Handler for image
*
* @package ThemePlate
* @since 0.1.0
*/
namespace ThemePlate;
use Error;
use Intervention\Image\ImageManager;
use ThemePlate\Image\Imager;
use ThemePlate\Process\Tasks;
/**
* @method static Imager register( string $name, int $width, int $height, bool $crop = false )
* @method static Imager manipulate( string $size, string $filter, array $args = array() )
* @method static Imager manager( ImageManager $manager )
* @method static Imager tasks( Tasks $tasks )
* @method static array action( array|false $image, int $attachment_id, string|int[] $size )
* @method static array dump()
*/
class Image {
private static ?Imager $imager = null;
public static function __callStatic( string $name, array $arguments ) {
if ( ! self::$imager instanceof Imager ) {
self::$imager = new Imager();
}
if ( method_exists( self::$imager, $name ) ) {
return call_user_func_array( array( self::$imager, $name ), $arguments );
}
throw new Error( 'Call to undefined method ' . __CLASS__ . '::' . $name . '()' );
}
public static function processor( Tasks $tasks = null ): ?Tasks {
if ( ! self::$imager instanceof Imager ) {
self::$imager = new Imager();
}
if ( null === $tasks && class_exists( Tasks::class ) ) {
$tasks = new Tasks( __CLASS__ );
}
if ( $tasks instanceof Tasks ) {
self::$imager->tasks( $tasks );
}
add_filter( 'wp_get_attachment_image_src', array( self::$imager, 'action' ), 10, 3 );
return $tasks;
}
}