Skip to content

Commit

Permalink
Merge pull request #10 from ingenerator/support-vips-thumbnail-size
Browse files Browse the repository at this point in the history
Support VIPS thumbnail size option to control whether to downsize, upsize or both
  • Loading branch information
craig410 authored Oct 17, 2024
2 parents f1bfe9b + 830c0ea commit c8a6a2d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
### Unreleased

### v2.2.0 (2024-10-17)

* Support `size` option on thumbnail() to control whether to upsize, downsize or both(default). See https://www.libvips.org/API/current/libvips-resample.html#vips-thumbnail

### v2.1.0 (2024-10-01)

* Support PHP 8.3
Expand Down
2 changes: 2 additions & 0 deletions src/Processor/ImageOperations.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Jcupitt\Vips\Extend;
use Jcupitt\Vips\Image;
use Jcupitt\Vips\Interpretation;
use Jcupitt\Vips\Size;
use JetBrains\PhpStorm\ArrayShape;

class ImageOperations implements ImageProcessorInterface
Expand Down Expand Up @@ -65,6 +66,7 @@ public function thumbnail(string $source_path, string $output_path, array $opera
$source_path, $operations['scale']['width'],
[
'height' => $operations['scale']['height'] ?? 10_000_000,
'size' => $operations['scale']['size'] ?? Size::BOTH,
'export-profile' => Interpretation::SRGB,
]
);
Expand Down
14 changes: 13 additions & 1 deletion test/unit/Processor/BaseImageProcessorTestCases.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
namespace test\unit\Processor;

use Ingenerator\ImageProcessing\Processor\ImageProcessorInterface;
use Jcupitt\Vips\Size;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Ingenerator\ImageProcessing\Processor\ImageCompare;
Expand Down Expand Up @@ -150,6 +151,14 @@ public static function providerThumbnailOperations(): array
],
self::RESOURCE_DIR.'read_alpha.png',
],
'Scale down only if src image greater than requested size, ie DO NOT SCALE UP' => [
self::RESOURCE_DIR.'porto_1024.jpg',
[
'scale' => ['width' => 1025, 'height' => 787, 'size' => Size::DOWN],
'save' => ['type' => 'webp'],
],
self::RESOURCE_DIR.'porto_1024.webp',
],
'Scale up' => [
self::RESOURCE_DIR.'logo.png',
[
Expand Down Expand Up @@ -198,7 +207,10 @@ public function test_thumbnail(string $source_image, array $operations, string $
pathinfo($path_expected_result, PATHINFO_EXTENSION)
);
$subject->thumbnail($source_image, $output_file, $operations);
$this->assertTrue(ImageCompare::isSame($path_expected_result, $output_file));
$this->assertTrue(
ImageCompare::isSame($path_expected_result, $output_file),
'Failed asserting that '.$output_file.' is same image as '.$path_expected_result
);
}

protected function setUp(): void
Expand Down

0 comments on commit c8a6a2d

Please sign in to comment.