Skip to content

Commit

Permalink
fixes #287
Browse files Browse the repository at this point in the history
* Fixes problem with red border in ellipse, arc and roundedRectangle

* Issues #287 - PHP 8.1

* Update src/claviska/SimpleImage.php

* Update src/claviska/SimpleImage.php

* Update src/claviska/SimpleImage.php

* Update src/claviska/SimpleImage.php

* Update src/claviska/SimpleImage.php

* Update src/claviska/SimpleImage.php

Co-authored-by: Cory LaViska <cory@abeautifulsite.net>
  • Loading branch information
maPer77 and claviska authored Dec 1, 2021
1 parent 21b6f4b commit 00f9066
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/claviska/SimpleImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class SimpleImage {
* @param string $image An image file or a data URI to load.
* @throws \Exception Thrown if the GD library is not found; file|URI or image data is invalid.
*/
public function __construct($image = null) {
public function __construct($image = '') {
// Check for the required GD extension
if(extension_loaded('gd')) {
// Ignore JPEG warnings that cause imagecreatefromjpeg() to fail
Expand Down Expand Up @@ -147,7 +147,7 @@ public function fromFile($file) {
// workaround to prevent imagepalettetruecolor() from borking transparency.
$width = imagesx($gif);
$height = imagesy($gif);
$this->image = imagecreatetruecolor($width, $height);
$this->image = imagecreatetruecolor((int) $width, (int) $height);
$transparentColor = imagecolorallocatealpha($this->image, 0, 0, 0, 127);
imagecolortransparent($this->image, $transparentColor);
imagefill($this->image, 0, 0, $transparentColor);
Expand Down Expand Up @@ -194,7 +194,7 @@ public function fromFile($file) {
* @return \claviska\SimpleImage
*/
public function fromNew($width, $height, $color = 'transparent') {
$this->image = imagecreatetruecolor($width, $height);
$this->image = imagecreatetruecolor((int) $width, (int) $height);

// Use PNG for dynamically created images because it's lossless and supports transparency
$this->mimeType = 'image/png';
Expand Down Expand Up @@ -490,7 +490,7 @@ protected static function imageCopyMergeAlpha($dstIm, $srcIm, $dstX, $dstY, $src
imagefilter($srcIm, IMG_FILTER_COLORIZE, 0, 0, 0, 127 * ((100 - $pct) / 100));
}

imagecopy($dstIm, $srcIm, $dstX, $dstY, $srcX, $srcY, $srcW, $srcH);
imagecopy($dstIm, $srcIm, (int) $dstX, (int) $dstY, (int) $srcX, (int) $srcY, (int) $srcW, (int) $srcH);

return true;
}
Expand Down Expand Up @@ -593,7 +593,7 @@ public function crop($x1, $y1, $x2, $y2) {
// Avoid using native imagecrop() because of a bug with PNG transparency
$dstW = abs($x2 - $x1);
$dstH = abs($y2 - $y1);
$newImage = imagecreatetruecolor($dstW, $dstH);
$newImage = imagecreatetruecolor((int) $dstW, (int) $dstH);
$transparentColor = imagecolorallocatealpha($newImage, 0, 0, 0, 127);
imagecolortransparent($newImage, $transparentColor);
imagefill($newImage, 0, 0, $transparentColor);
Expand All @@ -603,10 +603,10 @@ public function crop($x1, $y1, $x2, $y2) {
$newImage,
$this->image,
0, 0, min($x1, $x2), min($y1, $y2),
$dstW,
$dstH,
$dstW,
$dstH
(int) $dstW,
(int) $dstH,
(int) $dstW,
(int) $dstH
);

// Swap out the new image
Expand Down Expand Up @@ -802,16 +802,16 @@ public function resize($width = null, $height = null) {
// We can't use imagescale because it doesn't seem to preserve transparency properly. The
// workaround is to create a new truecolor image, allocate a transparent color, and copy the
// image over to it using imagecopyresampled.
$newImage = imagecreatetruecolor($width, $height);
$newImage = imagecreatetruecolor((int) $width, (int) $height);
$transparentColor = imagecolorallocatealpha($newImage, 0, 0, 0, 127);
imagecolortransparent($newImage, $transparentColor);
imagefill($newImage, 0, 0, $transparentColor);
imagecopyresampled(
$newImage,
$this->image,
0, 0, 0, 0,
$width,
$height,
(int) $width,
(int) $height,
$this->getWidth(),
$this->getHeight()
);
Expand Down Expand Up @@ -1885,7 +1885,7 @@ protected function allocateColor($color) {
$color['red'],
$color['green'],
$color['blue'],
127 - ($color['alpha'] * 127)
(int) (127 - ($color['alpha'] * 127))
);
if($index > -1) {
// Yes, return this color index
Expand Down

0 comments on commit 00f9066

Please sign in to comment.