Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fix: strict type check in Editor blend functions #25

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Grafika/EditorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function apply( &$image, $filter );
*
* @return EditorInterface An instance of Editor.
*/
public function blend(&$image1, $image2, $type='normal', $opacity = 1.0, $position = 'top-left', $offsetX = 0, $offsetY = 0 );
public function blend(ImageInterface &$image1, ImageInterface $image2, $type = 'normal', float $opacity = 1.0, string $position = 'top-left', int $offsetX = 0, int $offsetY = 0);

/**
* Compare two images and returns a hamming distance. A value of 0 indicates a likely similar picture. A value between 1 and 10 is potentially a variation. A value greater than 10 is likely a different image.
Expand Down Expand Up @@ -252,4 +252,4 @@ public function save( $image, $file, $type = null, $quality = null, $interlace =
*/
public function text( &$image, $text, $size = 12, $x = 0, $y = 12, $color = null, $font = '', $angle = 0 );

}
}
6 changes: 3 additions & 3 deletions src/Grafika/Gd/Editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function apply( &$image, $filter)
* @return Editor
* @throws \Exception When added image is outside of canvas or invalid blend type
*/
public function blend(&$image1, $image2, $type='normal', $opacity = 1.0, $position = 'top-left', $offsetX = 0, $offsetY = 0 ){
public function blend(ImageInterface &$image1, ImageInterface $image2, $type='normal', float $opacity = 1.0, string $position = 'top-left', int $offsetX = 0, int $offsetY = 0) {

// Turn into position object
$position = new Position($position, $offsetX, $offsetY);
Expand Down Expand Up @@ -113,7 +113,7 @@ public function blend(&$image1, $image2, $type='normal', $opacity = 1.0, $positi

$type = strtolower( $type );
if($type==='normal') {
if ( $opacity !== 1 ) {
if ( $opacity !== 1.0 ) {
$this->opacity($image2, $opacity);
}
imagecopy( $canvas, $gd2, $loopStartX + $offsetX, $loopStartY + $offsetY, 0, 0, $image2->getWidth(), $image2->getHeight());
Expand Down Expand Up @@ -1176,4 +1176,4 @@ private function _smartCrop($oldImage, $cropW, $cropH){

return array($x,$y);
}
}
}
8 changes: 4 additions & 4 deletions src/Grafika/Imagick/Editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ public function apply(&$image, $filter)
* @return Editor
* @throws \Exception When added image is outside of canvas or invalid blend type
*/
public function blend(&$image1, $image2, $type='normal', $opacity = 1.0, $position = 'top-left', $offsetX = 0, $offsetY = 0 ){

public function blend(ImageInterface &$image1, ImageInterface $image2, $type = 'normal', float $opacity = 1.0, string $position = 'top-left', int $offsetX = 0, int $offsetY = 0)
{
// Turn into position object
$position = new Position($position, $offsetX, $offsetY);

Expand Down Expand Up @@ -86,7 +86,7 @@ public function blend(&$image1, $image2, $type='normal', $opacity = 1.0, $positi
$loopStartY += $diff;
}

if ( $opacity !== 1 ) {
if ( $opacity !== 1.0 ) {
$this->opacity($image2, $opacity);
}

Expand Down Expand Up @@ -824,4 +824,4 @@ private function _getImageTypeFromFileName($imageFile)
}
}

}
}