Skip to content

Commit

Permalink
lib(resize): throw Exception instead of InvalidArgumentException
Browse files Browse the repository at this point in the history
  • Loading branch information
andi34 authored Nov 18, 2023
1 parent 0b79746 commit dc8edf6
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/resize.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
function rotateResizeImage($image, $rotation, $bg_color = '#ffffff') {
try {
if (!$image) {
throw new InvalidArgumentException('Invalid image resource');
throw new Exception('Invalid image resource');
}

// simple rotate if possible and ignore changed dimensions (doesn't need to care about background color)
Expand Down Expand Up @@ -76,14 +76,14 @@ function rotateResizeImage($image, $rotation, $bg_color = '#ffffff') {
function resizeImage($image, $max_width, $max_height) {
try {
if (!$image) {
throw new InvalidArgumentException('Invalid image resource.');
throw new Exception('Invalid image resource.');
}

$old_width = imagesx($image);
$old_height = imagesy($image);

if ($old_width <= 0 || $old_height <= 0 || $max_width <= 0 || $max_height <= 0) {
throw new InvalidArgumentException('Invalid image dimensions or maximum dimensions.');
throw new Exception('Invalid image dimensions or maximum dimensions.');
}

$scale = min($max_width / $old_width, $max_height / $old_height);
Expand All @@ -106,13 +106,13 @@ function resizeImage($image, $max_width, $max_height) {
function resizePngImage($image, $new_width, $new_height) {
try {
if (!$image) {
throw new InvalidArgumentException('Invalid image resource.');
throw new Exception('Invalid image resource.');
}

$old_width = imagesx($image);
$old_height = imagesy($image);
if ($old_width <= 0 || $old_height <= 0 || $new_width <= 0 || $new_height <= 0) {
throw new InvalidArgumentException('Invalid image dimensions or maximum dimensions.');
throw new Exception('Invalid image dimensions or maximum dimensions.');
}
$new = imagecreatetruecolor($new_width, $new_height);
if (!$new) {
Expand Down Expand Up @@ -141,7 +141,7 @@ function resizeCropImage($max_width, $max_height, $source_file, $quality = 100)
$old_width = intval(imagesx($source_file));
$old_height = intval(imagesy($source_file));
if ($old_width <= 0 || $old_height <= 0 || $max_width <= 0 || $max_height <= 0) {
throw new InvalidArgumentException('Invalid image dimensions or maximum dimensions.');
throw new Exception('Invalid image dimensions or maximum dimensions.');
}
$new_width = intval(($old_height * $max_width) / $max_height);
$new_height = intval(($old_width * $max_height) / $max_width);
Expand Down

0 comments on commit dc8edf6

Please sign in to comment.