Update simple-image.class.php

Fix float to int deprecation message
This commit is contained in:
Sebastian 2023-02-22 21:48:18 +01:00 committed by GitHub
parent 5c260d82f4
commit 550a46f10f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -774,11 +774,11 @@ class SimpleImage {
/** /**
* Resize an image to the specified dimensions. If only one dimension is specified, the image will be resized proportionally. * Resize an image to the specified dimensions. If only one dimension is specified, the image will be resized proportionally.
* *
* @param integer $width The new image width. * @param int|null $width The new image width.
* @param integer $height The new image height. * @param int|null $height The new image height.
* @return \claviska\SimpleImage * @return \claviska\SimpleImage
*/ */
public function resize($width = null, $height = null) { public function resize(?int $width, ?int $height) {
// No dimentions specified // No dimentions specified
if(!$width && !$height) { if(!$width && !$height) {
return $this; return $this;
@ -786,12 +786,12 @@ class SimpleImage {
// Resize to width // Resize to width
if($width && !$height) { if($width && !$height) {
$height = $width / $this->getAspectRatio(); $height = (int)$width / $this->getAspectRatio();
} }
// Resize to height // Resize to height
if(!$width && $height) { if(!$width && $height) {
$width = $height * $this->getAspectRatio(); $width = (int)$height * $this->getAspectRatio();
} }
// If the dimensions are the same, there's no need to resize // If the dimensions are the same, there's no need to resize
@ -802,7 +802,7 @@ class SimpleImage {
// We can't use imagescale because it doesn't seem to preserve transparency properly. The // 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 // workaround is to create a new truecolor image, allocate a transparent color, and copy the
// image over to it using imagecopyresampled. // image over to it using imagecopyresampled.
$newImage = imagecreatetruecolor($width, $height); $newImage = imagecreatetruecolor((int)$width, (int)$height);
$transparentColor = imagecolorallocatealpha($newImage, 0, 0, 0, 127); $transparentColor = imagecolorallocatealpha($newImage, 0, 0, 0, 127);
imagecolortransparent($newImage, $transparentColor); imagecolortransparent($newImage, $transparentColor);
imagefill($newImage, 0, 0, $transparentColor); imagefill($newImage, 0, 0, $transparentColor);
@ -810,8 +810,8 @@ class SimpleImage {
$newImage, $newImage,
$this->image, $this->image,
0, 0, 0, 0, 0, 0, 0, 0,
$width, (int)$width,
$height, (int)$height,
$this->getWidth(), $this->getWidth(),
$this->getHeight() $this->getHeight()
); );