Skip to content

Commit

Permalink
minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
vendeeglobe committed May 30, 2022
1 parent 7249392 commit b5f9267
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 27 deletions.
56 changes: 31 additions & 25 deletions wacko/lib/phpthumb/GD.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,9 @@ public function pad($width, $height, array $color = [255, 255, 255]): GD
);

// update all the variables and resources to be correct
$this->oldImage = $this->workingImage;
$this->currentDimensions['width'] = $width;
$this->currentDimensions['height'] = $height;
$this->oldImage = $this->workingImage;
$this->currentDimensions['width'] = $width;
$this->currentDimensions['height'] = $height;

return $this;
}
Expand Down Expand Up @@ -230,9 +230,12 @@ public function resize(int $maxWidth = 0, int $maxHeight = 0): GD
$this->calcImageSize($this->currentDimensions['width'], $this->currentDimensions['height']);

// create the working image
if (function_exists('imagecreatetruecolor')) {
if (function_exists('imagecreatetruecolor'))
{
$this->workingImage = imagecreatetruecolor($this->newDimensions['newWidth'], $this->newDimensions['newHeight']);
} else {
}
else
{
$this->workingImage = imagecreate($this->newDimensions['newWidth'], $this->newDimensions['newHeight']);
}

Expand Down Expand Up @@ -816,20 +819,23 @@ public function show(bool $rawData = false): GD

switch ($this->format) {
case 'GIF':
if ($rawData === false) {
if ($rawData === false)
{
header('Content-type: image/gif');
}
imagegif($this->oldImage);
break;
case 'JPG':
if ($rawData === false) {
if ($rawData === false)
{
header('Content-type: image/jpeg');
}
imagejpeg($this->oldImage, null, $this->options['jpegQuality']);
break;
case 'PNG':
case 'STRING':
if ($rawData === false) {
if ($rawData === false)
{
header('Content-type: image/png');
}
imagepng($this->oldImage);
Expand Down Expand Up @@ -877,7 +883,7 @@ public function save(string $fileName, string $format = null): GD

if (!in_array($format, $validFormats))
{
throw new \InvalidArgumentException("Invalid format type specified in save function: ".$format);
throw new \InvalidArgumentException("Invalid format type specified in save function: " . $format);
}

// make sure the directory is writeable
Expand All @@ -891,12 +897,12 @@ public function save(string $fileName, string $format = null): GD
// throw an exception if not writeable
if (!is_writeable(dirname($fileName)))
{
throw new \RuntimeException("File is not writeable, and could not correct permissions: ".$fileName);
throw new \RuntimeException("File is not writeable, and could not correct permissions: " . $fileName);
}
}
else
{ // throw an exception if not writeable
throw new \RuntimeException("File not writeable: ".$fileName);
throw new \RuntimeException("File not writeable: " . $fileName);
}
}

Expand Down Expand Up @@ -940,14 +946,14 @@ public function setOptions(array $options = []): GD
if (sizeof($this->options) == 0)
{
$defaultOptions = [
'resizeUp' => false,
'jpegQuality' => 100,
'resizeUp' => false,
'jpegQuality' => 100,
'correctPermissions' => false,
'preserveAlpha' => true,
'preserveAlpha' => true,
'alphaMaskColor' => [255, 255, 255],
'preserveTransparency' => true,
'transparencyMaskColor' => [0, 0, 0],
'interlace' => null
'preserveTransparency' => true,
'transparencyMaskColor' => [0, 0, 0],
'interlace' => null
];
}
else
Expand Down Expand Up @@ -1133,7 +1139,7 @@ public function setWorkingImage(object $workingImage): GD
/**
* Calculates a new width and height for the image based on $this->maxWidth and the provided dimensions
*
* @param int $width
* @param int $width
* @param int $height
*@return array
*/
Expand All @@ -1151,14 +1157,14 @@ protected function calcWidth(int $width, int $height): array
/**
* Calculates a new width and height for the image based on $this->maxWidth and the provided dimensions
*
* @param int $width
* @param int $width
* @param int $height
*@return array
*/
protected function calcHeight(int $width, int $height): array
{
$newHeightPercentage = (100 * $this->maxHeight) / $height;
$newWidth = ($width * $newHeightPercentage) / 100;
$newHeightPercentage = (100 * $this->maxHeight) / $height;
$newWidth = ($width * $newHeightPercentage) / 100;

return [
'newWidth' => ceil($newWidth),
Expand All @@ -1169,7 +1175,7 @@ protected function calcHeight(int $width, int $height): array
/**
* Calculates a new width and height for the image based on $this->percent and the provided dimensions
*
* @param int $width
* @param int $width
* @param int $height
*@return array
*/
Expand Down Expand Up @@ -1309,11 +1315,11 @@ protected function determineFormat()
{
if ($this->remoteImage)
{
throw new \Exception("Could not determine format of remote image: ".$this->fileName);
throw new \Exception("Could not determine format of remote image: " . $this->fileName);
}
else
{
throw new \Exception("File is not a valid image: ".$this->fileName);
throw new \Exception("File is not a valid image: " . $this->fileName);
}
}

Expand Down Expand Up @@ -1350,7 +1356,7 @@ protected function verifyFormatCompatiblity()

if (!$isCompatible)
{
throw new \Exception("Your GD installation does not support ".$this->format." image types");
throw new \Exception("Your GD installation does not support " . $this->format . " image types");
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions wacko/lib/phpthumb/Plugins/Reflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,11 +249,11 @@ protected function imageFlipVertical ()
protected function hex2rgb ($hex, $asString = false)
{
// strip off any leading #
if (0 === strpos($hex, '#'))
if (str_starts_with($hex, '#'))
{
$hex = substr($hex, 1);
}
elseif (0 === strpos($hex, '&H'))
elseif (str_starts_with($hex, '&H'))
{
$hex = substr($hex, 2);
}
Expand Down

0 comments on commit b5f9267

Please sign in to comment.