Skip to content

Commit 78e0951

Browse files
author
Sebastian Neubert
committed
Issue #1: Use Imagick to crop the image
1 parent 4fff1ff commit 78e0951

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

module/VisualCeption.php

100644100755
Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ private function getExpectedScreenshotPath ($identifier)
7272
return $this->referenceImageDir . $this->getScreenshotName($identifier);
7373
}
7474

75-
private function createScreenshot ($identifier, $coords)
75+
private function createScreenshot ($identifier, array $coords)
7676
{
7777
$webDriverModule = $this->getModule("WebDriver");
7878
$webDriver = $webDriverModule->webDriver;
@@ -82,13 +82,11 @@ private function createScreenshot ($identifier, $coords)
8282

8383
$webDriver->takeScreenshot($screenshotPath);
8484

85-
$screenshotImage = imagecreatefrompng($screenshotPath);
86-
$elementImage = \imagecreatetruecolor($coords['width'], $coords['height']);
87-
88-
list ($current_width, $current_height) = \getimagesize($screenshotPath);
89-
imagecopy($elementImage, $screenshotImage, 0, 0, $coords['offset_x'], $coords['offset_y'], $current_width, $current_height);
90-
91-
$result = \imagepng($elementImage, $elementPath, 0);
85+
// # $screenshotImage = imagecreatefrompng($screenshotPath);
86+
$screenShotImage = new \Imagick();
87+
$screenShotImage->readImage( $screenshotPath );
88+
$screenShotImage->cropImage( $coords['width'], $coords['height'], $coords['offset_x'], $coords['offset_y'] );
89+
$screenShotImage->writeImage( $elementPath );
9290

9391
unlink($screenshotPath);
9492

0 commit comments

Comments
 (0)