Skip to content

Commit

Permalink
use constant for image types
Browse files Browse the repository at this point in the history
  • Loading branch information
jamadam committed Apr 30, 2024
1 parent 72fa114 commit 64948d1
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions php/lib/thumbnail_lib.php
Expand Up @@ -144,16 +144,16 @@ private function load_image () {
list($this->src_w, $this->src_h, $this->src_type, $this->src_attr) = getimagesize($src_file);

switch($this->src_type) {
case 1: #GIF
case IMAGETYPE_GIF:
$this->src_img = @imagecreatefromgif($src_file);
break;
case 2: #JPEG
case IMAGETYPE_JPEG:
$this->src_img = @imagecreatefromjpeg($src_file);
break;
case 3: #PNG
case IMAGETYPE_PNG:
$this->src_img = @imagecreatefrompng($src_file);
break;
case 18: #WEBP
case IMAGETYPE_WEBP:
$this->src_img = @imagecreatefromwebp($src_file);
break;
default: #Unsupported format
Expand Down Expand Up @@ -231,27 +231,27 @@ private function _make_dest_name ($w, $h) {
if ($this->dest_type == 'auto') {
$output = $this->src_type;
} elseif (strtolower($this->dest_type) == 'gif') {
$output = 1;
$output = IMAGETYPE_GIF;
} elseif (strtolower($this->dest_type) == 'jpeg') {
$output = 2;
$output = IMAGETYPE_JPEG;
} elseif (strtolower($this->dest_type) == 'png') {
$output = 3;
$output = IMAGETYPE_PNG;
} elseif (strtolower($this->dest_type) == 'webp') {
$output = 18;
$output = IMAGETYPE_WEBP;
} else {
$output = $this->src_type;
}
switch($output) {
case 1:
case IMAGETYPE_GIF:
$ext = '.gif';
break;
case 2:
case IMAGETYPE_JPEG:
$ext = '.jpg';
break;
case 3:
case IMAGETYPE_PNG:
$ext = '.png';
break;
case 18:
case IMAGETYPE_WEBP:
$ext = '.webp';
break;
default:
Expand Down Expand Up @@ -398,27 +398,27 @@ public function get_thumbnail ($args = null) {
$output = $this->src_type;
if ($this->dest_type != 'auto') {
if ( strtolower($this->dest_type) == 'gif' )
$output = 1;
$output = IMAGETYPE_GIF;
elseif ( strtolower($this->dest_type) == 'jpeg' )
$output = 2;
$output = IMAGETYPE_JPEG;
elseif ( strtolower($this->dest_type) == 'png' )
$output = 3;
$output = IMAGETYPE_PNG;
elseif ( strtolower($this->dest_type) == 'webp' )
$output = 18;
$output = IMAGETYPE_WEBP;
else
$output = $this->src_type;
}
switch($output) {
case 1: #GIF
case IMAGETYPE_GIF:
imagegif($this->dest_img, $dest_file);
break;
case 2: #JPEG
case IMAGETYPE_JPEG:
imagejpeg($this->dest_img, $dest_file);
break;
case 3: #PNG
case IMAGETYPE_PNG:
imagepng($this->dest_img, $dest_file);
break;
case 18: #PNG
case IMAGETYPE_WEBP:
imagewebp($this->dest_img, $dest_file);
break;
}
Expand Down

0 comments on commit 64948d1

Please sign in to comment.