Skip to content

Commit

Permalink
add crop
Browse files Browse the repository at this point in the history
  • Loading branch information
freekmurze committed Sep 5, 2023
1 parent e0a2ed5 commit e7b45e2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
9 changes: 4 additions & 5 deletions src/Drivers/Gd/GdImageDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,18 +149,17 @@ protected function modify(
imagesavealpha($modified, true);
}

// copy content from resource
imagecopyresampled(
$modified,
$this->image,
0,
0,
0,
0,
$sourceX,
$sourceY,
$desiredWidth,
$desiredHeight,
$desiredWidth,
$desiredHeight,
$originalWidth,
$originalHeight
);

$this->image = $modified;
Expand Down
7 changes: 3 additions & 4 deletions tests/Manipulations/ManualCropTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
use Spatie\Image\Image;

it('can contain an image in the given dimensions', function (
ImageDriver $driver,
array $dimensions,
int $expectedWidth,
int $expectedHeight,
) {
$driver = Image::useImageDriver('gd');

$targetFile = $this->tempDir->path("{$driver->driverName()}/manual-crop.jpg");

$driver->load(getTestJpg())->manualCrop(...$dimensions)->save($targetFile);
Expand All @@ -20,6 +19,6 @@
$savedImage = $driver->load($targetFile);
expect($savedImage->getWidth())->toBe($expectedWidth);
expect($savedImage->getHeight())->toBe($expectedHeight);
})->with([
[[1, 2,3,4], 0, 0],
})->with('drivers')->with([
[[100, 50, 0, 50], 100, 50],
]);

0 comments on commit e7b45e2

Please sign in to comment.