-
Notifications
You must be signed in to change notification settings - Fork 0
/
ImageResizer.php
107 lines (94 loc) · 2.75 KB
/
ImageResizer.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php
/**
* Plugin Name: Image Resizer
* Plugin URI: https://www.siatex.com
* Description: Generate Multiple size Of Image in Media
* Author: SiATEX
* Author URI: https://www.siatex.com
* Version: 2.5.2
*/
namespace ImageResizer;
use ImageResizer\lib\Resizer;
use ImageResizer\lib\SizeBuilder;
define('ImageResizer', dirname(__FILE__));
//Define
define("IMRLIB", ImageResizer . "/lib/");
define("IMR_ASSET_URI", plugin_dir_url(__FILE__) . "assets/");
define("IMR_ASSET_DIR", plugin_dir_path(__FILE__) . "assets/");
foreach (glob(IMRLIB . "*.php") as $filename) {
include $filename;
}
define('IMAGE_TYPES', ['jpg', 'jpeg', 'png', 'gif', 'webp', 'bmp', 'JPG']);
/**
* Description of ImageResizer
*
* @author Apon
*/
//Functions
//wp_get_attachment_image_srcset
//Meta
//_wp_attached_file
//_wp_attachment_metadata
class ImageResizer
{
public $option;
private $optionKey = "media_resize_options";
//put your code here
public function __construct()
{
$this->setOption();
$this->mediaSizeSet();
if (is_admin()) {
$this->builder = new SizeBuilder($this->option);
//$this->resize = new Resizer($this->option);
$this->adminView = new lib\AdminView($this->option);
}
//Ajax Hook Register
add_action('wp_ajax_media_resize_option', [$this, 'media_resize_option']);
}
/**
* Set Options
*/
function setOption()
{
$lastBuild = get_option('lastBuildProcess');
$this->option = [
'allow_extensions' => IMAGE_TYPES,
'maxItemResize' => 1,
'replace_existingSize' => 1,
'lastBuild' => empty($lastBuild) ? 0 : $lastBuild,
'imageQuality' => 100,
'media-size' => [
['name' => 'small-size', 'width' => 100, 'height' => 100],
['name' => 'thumbnail', 'width' => 150, 'height' => 150],
['name' => 'medium', 'width' => 300, 'height' => 300],
]
];
$optString = get_option($this->optionKey);
if (!empty($optString)) {
$optArr = json_decode($optString, true);
$this->option = array_merge($this->option, $optArr);
}
}
public function mediaSizeSet()
{
foreach ($this->option['media-size'] as $size) {
add_image_size($size['name'], $size['width'], $size['height'], false);
}
}
/**
* Ajax Callback of Media Resize Option store
*
*/
function media_resize_option()
{
$data = [];
parse_str($_POST['data'], $data);
$options = json_encode($data);
update_option($this->optionKey, $options);
echo 1;
wp_die();
}
}
$imageResizer = new ImageResizer();
//var_dump($imageResizer);