Skip to content

armgit / Vvveb

Public Imported from GitHub
0

Powerful and easy to use cms to build websites, blogs or ecommerce stores.

Resize method for images

givanz582997719035
diff --git a/system/images.php b/system/images.php
index 4890243..421be78 100755
--- a/system/images.php
+++ b/system/images.php
@@ -131,7 +131,7 @@ class Images {
return $image;
}
- static public function images($images, $type, $size = '') {
+ static public function images($images, $type, $size = '', $method = 'cs') {
foreach ($images as $key => &$image) {
$image['image'] = Images::image($image['image'], $type, $size);
}
diff --git a/system/media/gd.php b/system/media/gd.php
index d981749..90ac576 100644
--- a/system/media/gd.php
+++ b/system/media/gd.php
@@ -113,6 +113,9 @@ class Image {
public function resize($width, $height = 0, $method = 's') {
switch ($method) {
+ case 'r':
+ return $this->_resize($width, $height);
+
case 's':
return $this->stretch($width, $height);
@@ -136,8 +139,23 @@ class Image {
}
if (! $height) {
- $height = $width * $newRatio;
+ $height = ceil($width / $newRatio);
}
+
+ $this->image = imagescale($this->image, $width, $height, IMG_BICUBIC_FIXED);
+ }
+
+ public function _resize($width, $height = 0) {
+ if (! $this->width || ! $this->height || ! $this->image) {
+ return;
+ }
+
+ $ratio = $newRatio = $this->width / $this->height;
+
+ if ($width && $height) {
+ $newRatio = $width / $height;
+ }
+
if ($width && $height) {
$scaleW = $width / $this->width;
diff --git a/system/media/imagick.php b/system/media/imagick.php
index 798d002..c1624d5 100644
--- a/system/media/imagick.php
+++ b/system/media/imagick.php
@@ -95,6 +95,9 @@ class Image {
}
switch ($method) {
+ case 'r':
+ return $this->_resize($width, $height);
+
case 's':
return $this->stretch($width, $height);
@@ -107,6 +110,25 @@ class Image {
}
public function stretch($width, $height = 0) {
+ $ratio = $newRatio = $this->width / $this->height;
+
+ if ($width && $height) {
+ $newRatio = $width / $height;
+ }
+
+ if (! $height) {
+ $height = ceil($width / $newRatio);
+ }
+
+ if (method_exists($this->image, 'adaptiveResizeImage')) {
+ return $this->image->adaptiveResizeImage($width, $height);
+ } else {
+ //$this->image->thumbnailImage($width, $height, true, true);
+ return $this->image->resizeImage($width, $height, \Imagick::FILTER_LANCZOS, 1, true);
+ }
+ }
+
+ public function _resize($width, $height = 0) {
//$this->width = $this->image->getImageWidth();
//$this->height = $this->image->getImageHeight();
@@ -116,10 +138,6 @@ class Image {
$newRatio = $width / $height;
}
- if (! $height) {
- $height = $width / $newRatio;
- }
-
if ($width && $height) {
$scaleW = $width / $this->width;
$scaleH = $height / $this->height;
@@ -179,6 +197,8 @@ class Image {
} else {
$newWidth = intval($width);
$newHeight = intval($height);
+ $crop_x = 0;
+ $crop_y = 0;
}
if ($this->width != $newWidth && $this->height != $newHeight) {