PluginProbe
Depicter — Popup & Slider Builder / trunk
Depicter — Popup & Slider Builder vtrunk
4.8.1 trunk 1.0.0 1.1.0 1.1.2 1.1.4 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.5 1.3.8 1.5.0 1.5.1 1.5.2 1.5.5 1.6.0 1.6.1 1.6.2 1.7.0 All 76 releases
depicter / app / src / Media / Image / ImageEditor.php

ImageEditor.php in Depicter — Popup & Slider Builder trunk, at app/src/Media/Image/ImageEditor.php

92 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Depicter\Media\Image;
3
4
5 use Depicter\Media\Uri;
6 use Depicter\Media\Url;
7
8 class ImageEditor
9 {
10 /**
11 * Shorthand method for calling resize and crop methods for an image.
12 *
13 * @param string $file Path or url of file or attachment ID
14 * @param int $resizeW Resize width
15 * @param int $resizeH Resize height
16 * @param int $cropW Crop with
17 * @param int $cropH Crop height
18 * @param array $args Resizing options
19 *
20 * @return mixed
21 */
22 public static function process( $file, $resizeW = null, $resizeH = null, $cropW = null, $cropH = null, $args = [] ){
23 try {
24 $resizer = new Resizer( $file );
25 return $resizer->process( $resizeW, $resizeH, $cropW, $cropH, $args );
26 } catch( ImageEditorException $exception ) {
27 return self::originalFile( $file );
28 }
29 }
30
31 /**
32 * Resize an image.
33 *
34 * @param string $file Path or url of file or attachment ID
35 * @param int $width Resize width
36 * @param int $height Resize height
37 * @param array $args Resizing options
38 *
39 * @return string
40 */
41 public static function resize( $file, $width = null, $height = null, $args = [] ){
42 try {
43 $resizer = new Resizer( $file );
44 return $resizer->resize( $width, $height, $args );
45 } catch( ImageEditorException $exception ) {
46 return self::originalFile( $file );
47 }
48 }
49
50 /**
51 * Crops an image
52 *
53 * @param string $file Path or url of file or attachment ID
54 * @param int $width Width to crop
55 * @param int $height Height to crop
56 * @param array $args Cropping options
57 *
58 * @return mixed
59 */
60 public static function crop( $file, $width = null, $height = null, $args = [] ){
61 try {
62 $resizer = new Resizer( $file );
63 return $resizer->crop( $width, $height, $args );
64 } catch( ImageEditorException $exception ) {
65 return self::originalFile( $file );
66 }
67 }
68
69 /**
70 * return original file
71 * @param $file
72 *
73 * @return mixed|string
74 */
75 public static function originalFile( $file ) {
76 if ( is_numeric( $file ) ) {
77 $attachment = wp_get_attachment_image_src( $file, 'full');
78 return $attachment ? $attachment[0] : '';
79 } else {
80 $urlHandler = new Url();
81 if ( $urlHandler->isUrl( $file ) ) {
82 return $file;
83 } else {
84 if ( file_exists( $file ) ) {
85 return Uri::toUrl($file);
86 }
87 }
88 }
89 return '';
90 }
91 }
92