Skip to content

Commit 397849c

Browse files
committed
Added crop and resize image resize method as default resize, fixed add new site automatic host generation from name
1 parent dd1fafa commit 397849c

File tree

6 files changed

+99
-9
lines changed

6 files changed

+99
-9
lines changed

admin/controller/settings/site.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ function index() {
256256
$view->set($data);
257257
$view->site = $site + $setting;
258258
$view->setting = $setting;
259-
$view->resize = ['s' => __('Stretch'), 'c' => __('Crop')];
259+
$view->resize = ['cs' => __('Crop & Resize'), 's' => __('Stretch'), 'c' => __('Crop')];
260260
$view->themeList = $themeList;
261261
$view->templateList = \Vvveb\getTemplateList(false, ['email']);
262262

install/sql/insert/site/site.sql

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
INSERT INTO `site` (`site_id`, `key`, `name`, `host`, `theme`, `template`, `settings`) VALUES
2-
(1, 'default','Default','*.*.*', 'landing', '', '{"description":{"1":{"title": "Vvveb","description": "The next generation website builder","meta-keywords": "cms, page builder, drag and drop, ecommerce, ecommerce platform, designer, developer, php, bootstrap 5","meta-description": "Powerful and easy to use drag and drop website builder for blogs, presentation or ecommerce stores","phone-number": "+55 (111) 123 777"}},"address":"West 21st Street Brooklyn NY","admin-email":"admin@admin.com","contact-email":"contact@admin.com","logo":"logo.png","logo-sticky":"logo.png","logo-dark":"logo-white.png","logo-dark-sticky":"logo-white.png","favicon":"favicon.ico","post_large_width":"800","post_large_height":"0","post_medium_width":"400","post_medium_height":"0","post_thumb_width":"150","post_thumb_height":"0","product_large_width":"800","product_large_height":"0","product_medium_width":"400","product_medium_height":"0","product_thumb_width":"150","product_thumb_height":"0","date_format":"F j, Y","time_format":"g:i A", "country_id":"223","region_id":"3655","language_id":"1","currency_id":"1","language":"en_US","currency":"USD","invoice_format":"I-{year2}-{month}-{order_id}-{user_id}-{customer_order_id}","order_id_format":"{rand-str-12}-{year2}","language_id":"1","currency_id":"1","length_type_id":"1","weight_type_id":"1","order_status_id":"1"}');
2+
(1, 'default','Default','*.*.*', 'landing', '', '{"description":{"1":{"title": "Vvveb","description": "The next generation website builder","meta-keywords": "cms, page builder, drag and drop, ecommerce, ecommerce platform, designer, developer, php, bootstrap 5","meta-description": "Powerful and easy to use drag and drop website builder for blogs, presentation or ecommerce stores","phone-number": "+55 (111) 123 777"}},"address":"West 21st Street Brooklyn NY","admin-email":"admin@admin.com","contact-email":"contact@admin.com","logo":"logo.png","logo-sticky":"logo.png","logo-dark":"logo-white.png","logo-dark-sticky":"logo-white.png","favicon":"favicon.ico","post_large_width":"800","post_large_height":"450","post_medium_width":"400","post_medium_height":"225","post_thumb_width":"150","post_thumb_height":"84","product_large_width":"800","product_large_height":"1021","product_medium_width":"400","product_medium_height":"510","product_thumb_width":"150","product_thumb_height":"190","date_format":"F j, Y","time_format":"g:i A", "country_id":"223","region_id":"3655","language_id":"1","currency_id":"1","language":"en_US","currency":"USD","invoice_format":"I-{year2}-{month}-{order_id}-{user_id}-{customer_order_id}","order_id_format":"{rand-str-12}-{year2}","language_id":"1","currency_id":"1","length_type_id":"1","weight_type_id":"1","order_status_id":"1"}');

system/images.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ static public function resize($src, $dest, $width, $height, $method) {
4646
return $img->save($dest);
4747
}
4848

49-
static public function image($image, $type = '', $size = '', $method = 's') {
49+
static public function image($image, $type = '', $size = '', $method = 'cs') {
5050
$publicPath = \Vvveb\publicUrlPath();
5151

5252
list($publicPath, $type, $image, $size) =
@@ -74,10 +74,10 @@ static public function image($image, $type = '', $size = '', $method = 's') {
7474
$site = siteSettings();
7575
$width = $site["{$type}_{$size}_width"] ?? 0;
7676
$height = $site["{$type}_{$size}_height"] ?? 0;
77-
$method = $site["{$type}_{$size}_method"] ?? 's';
77+
$method = $site["{$type}_{$size}_method"] ?? 'cs';
7878
}
7979

80-
$image = self::size($image,"{$width}x{$height}");
80+
$image = self::size($image,"{$width}x{$height}_$method");
8181

8282
if ($width || $height) {
8383
if (file_exists(DIR_PUBLIC . $cacheFolder . $image)) {

system/media/gd.php

+48-1
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,32 @@ public function save($file, $quality = 80, $extension = false) {
109109
}
110110
}
111111

112-
public function resize($width, $height, $method = 's') {
112+
public function resize($width, $height = 0, $method = 's') {
113+
switch ($method) {
114+
case 's':
115+
return $this->stretch($width, $height);
116+
117+
case 'c':
118+
return $this->crop($width, $height);
119+
120+
case 'cs':
121+
return $this->cropsize($width, $height);
122+
}
123+
}
124+
125+
public function stretch($width, $height = 0) {
113126
if (! $this->width || ! $this->height) {
114127
return;
115128
}
116129

117130
if ($width && $height) {
131+
$scaleW = $width / $this->width;
132+
$scaleH = $height / $this->height;
133+
134+
$scale = min($scaleW, $scaleH);
135+
136+
$width = (int)($this->width * $scale);
137+
$height = (int)($this->height * $scale);
118138
} else {
119139
if ($width) {
120140
$height = ceil($this->height / ($this->width / $width));
@@ -141,4 +161,31 @@ public function crop($topX, $topY, $bottomX, $bottomY) {
141161
$this->width = $bottomX - $topX;
142162
$this->height = $bottomY - $topY;
143163
}
164+
165+
public function cropsize($width, $height = 0) {
166+
if (! $this->width || ! $this->height) {
167+
return;
168+
}
169+
170+
$width = $width ?: $height;
171+
$height = $height ?: $width;
172+
173+
$newRatio = $width / $height;
174+
$ratio = $this->width / $this->height;
175+
176+
if ($newRatio > $ratio) {
177+
$newWidth = $width;
178+
$newHeight = floor($width / $this->width * $this->height);
179+
$crop_x = 0;
180+
$crop_y = intval(($newHeight - $height) / 2);
181+
} else {
182+
$newWidth = floor($height / $this->height * $this->width);
183+
$newHeight = $height;
184+
$crop_x = intval(($newWidth - $width) / 2);
185+
$crop_y = 0;
186+
}
187+
188+
$this->image = imagescale($this->image, $newWidth, $newHeight, IMG_BICUBIC_FIXED);
189+
$this->image = imagecrop($this->image, ['x' => 0, 'y' => 0, 'width' => $width, 'height' => $height]);
190+
}
144191
}

system/media/imagick.php

+45-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ public function __construct($file) {
3838
$this->file = $file;
3939
$this->image = new \Imagick();
4040
$this->image->readImage($file);
41-
4241
$this->width = $this->image->getImageWidth();
4342
$this->height = $this->image->getImageHeight();
4443
$this->mime = $this->image->getFormat();
@@ -82,15 +81,35 @@ public function save($file, $quality = 80, $extension = false) {
8281
return $this->image->writeImage($file);
8382
}
8483

85-
public function resize($width = 0, $height = 0, $method = 's') {
84+
public function resize($width, $height = 0, $method = 's') {
8685
if (! $this->width || ! $this->height) {
8786
return;
8887
}
8988

89+
switch ($method) {
90+
case 's':
91+
return $this->stretch($width, $height);
92+
93+
case 'c':
94+
return $this->crop($width, $height);
95+
96+
case 'cs':
97+
return $this->cropsize($width, $height);
98+
}
99+
}
100+
101+
public function stretch($width, $height = 0) {
90102
//$this->width = $this->image->getImageWidth();
91103
//$this->height = $this->image->getImageHeight();
92104

93105
if ($width && $height) {
106+
$scaleW = $width / $this->width;
107+
$scaleH = $height / $this->height;
108+
109+
$scale = min($scaleW, $scaleH);
110+
111+
$width = (int)($this->width * $scale);
112+
$height = (int)($this->height * $scale);
94113
} else {
95114
if ($width) {
96115
$height = ceil($this->height / ($this->width / $width));
@@ -115,4 +134,28 @@ public function crop($top_x, $top_y, $bottom_x, $bottom_y) {
115134
$this->width = $this->image->getImageWidth();
116135
$this->height = $this->image->getImageHeight();
117136
}
137+
138+
public function cropsize($width, $height = 0) {
139+
$width = $width ?: $height;
140+
$height = $height ?: $width;
141+
142+
$newRatio = $width / $height;
143+
$ratio = $this->width / $this->height;
144+
145+
if ($newRatio > $ratio) {
146+
$new_width = $width;
147+
$new_height = floor($width / $this->width * $this->height);
148+
$crop_x = 0;
149+
$crop_y = intval(($new_height - $height) / 2);
150+
} else {
151+
$new_width = floor($height / $this->height * $this->width);
152+
$new_height = $height;
153+
$crop_x = intval(($new_width - $width) / 2);
154+
$crop_y = 0;
155+
}
156+
157+
$this->image->resizeImage($new_width, $new_height, \Imagick::FILTER_LANCZOS, 1, true);
158+
159+
$this->image->cropImage($width, $height, $crop_x, $crop_y);
160+
}
118161
}

0 commit comments

Comments
 (0)