Skip to content

armgit / Vvveb

Public Imported from GitHub
0

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

Custom size for image resize

givanzed6847b22d45
diff --git a/system/images.php b/system/images.php
index abe791e..8dd18cd 100755
--- a/system/images.php
+++ b/system/images.php
@@ -36,13 +36,13 @@ use Vvveb\System\Media\Image;
class Images {
static public function resize($src, $dest, $width, $height, $method) {
@mkdir(dirname($dest), (0755 & ~umask()), true);
- $img = new Image($src);
- $img->resize($width,$height, $method);
+ $img = new Image($src);
+ $result = $img->resize($width,$height, $method);
return $img->save($dest);
}
- static public function image($image, $type = '', $size = '') {
+ static public function image($image, $type = '', $size = '', $method = 's') {
$publicPath = \Vvveb\publicUrlPath();
list($publicPath, $type, $image, $size) =
@@ -63,10 +63,15 @@ class Images {
$src = $image;
if ($size) {
- $site = siteSettings();
- $width = $site["{$type}_{$size}_width"] ?? 0;
- $height = $site["{$type}_{$size}_height"] ?? 0;
- $method = $site["{$type}_{$size}_method"] ?? 's';
+ if (is_array($size)) {
+ $width = $size[0];
+ $height = $size[1];
+ } else {
+ $site = siteSettings();
+ $width = $site["{$type}_{$size}_width"] ?? 0;
+ $height = $site["{$type}_{$size}_height"] ?? 0;
+ $method = $site["{$type}_{$size}_method"] ?? 's';
+ }
$image = self::size($image,"{$width}x{$height}");
diff --git a/system/media/gd.php b/system/media/gd.php
index f437dd9..207948d 100755
--- a/system/media/gd.php
+++ b/system/media/gd.php
@@ -39,20 +39,22 @@ class Image {
$info = getimagesize($file);
- $this->width = $info[0];
- $this->height = $info[1];
- $this->mime = $info['mime'] ?? '';
-
- if ($this->mime == 'image/gif') {
- $this->image = imagecreatefromgif($file);
- } elseif ($this->mime == 'image/png') {
- $this->image = imagecreatefrompng($file);
-
- imageinterlace($this->image, false);
- } elseif ($this->mime == 'image/jpeg') {
- $this->image = imagecreatefromjpeg($file);
- } elseif ($this->mime == 'image/webp') {
- $this->image = imagecreatefromwebp($file);
+ if ($info) {
+ $this->width = $info[0];
+ $this->height = $info[1];
+ $this->mime = $info['mime'] ?? '';
+
+ if ($this->mime == 'image/gif') {
+ $this->image = imagecreatefromgif($file);
+ } elseif ($this->mime == 'image/png') {
+ $this->image = imagecreatefrompng($file);
+
+ imageinterlace($this->image, false);
+ } elseif ($this->mime == 'image/jpeg') {
+ $this->image = imagecreatefromjpeg($file);
+ } elseif ($this->mime == 'image/webp') {
+ $this->image = imagecreatefromwebp($file);
+ }
}
} else {
//throw new \Exception("Could not load image $file");
@@ -88,6 +90,8 @@ class Image {
$extension = $extension ?: strtolower($info['extension']);
+ $result = false;
+
if (is_object($this->image) || is_resource($this->image)) {
if ($extension == 'jpeg' || $extension == 'jpg') {
$result = imagejpeg($this->image, $file, $quality);