From 716d67c5078275e7b4fde7716d96b37e8ffbb90e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Munsch?= Date: Mon, 30 Mar 2020 18:00:22 +0200 Subject: [PATCH] Add some fixes on original Jquery plugin FIX Exception in ImageLib.php This is a small patch for a bigger problem !! This lib should use laravel mechnism. TODO ! update version to 0.0.7 --- composer.json | 2 +- src/ResponsiveFileManager/ImageLib.php | 227 ++++++++++---------- src/ResponsiveFileManager/UploadHandler.php | 73 ++++--- 3 files changed, 158 insertions(+), 144 deletions(-) diff --git a/composer.json b/composer.json index 8f7a8e6..fb51cf9 100644 --- a/composer.json +++ b/composer.json @@ -7,7 +7,7 @@ "name": "Jeremy Munsch" } ], - "version": "0.0.6", + "version": "0.0.7", "keywords": ["laravel", "responsive", "filemanager"], "minimum-stability": "dev", "require": { diff --git a/src/ResponsiveFileManager/ImageLib.php b/src/ResponsiveFileManager/ImageLib.php index 8dac879..c9d97d0 100755 --- a/src/ResponsiveFileManager/ImageLib.php +++ b/src/ResponsiveFileManager/ImageLib.php @@ -1,7 +1,9 @@ 255, 'g' => 255, 'b' => 255 ); + private $fillColorArray = array('r' => 255, 'g' => 255, 'b' => 255); - private $sharpenArray = array( 'jpg' ); + private $sharpenArray = array('jpg'); private $psdReaderPath; private $filterOverlayPath; @@ -220,11 +222,11 @@ class ImageLib public function __construct($fileName) { - if (! $this->testGDInstalled()) { + if (!$this->testGDInstalled()) { if ($this->debug) { - throw new Exception('The GD Library is not installed.'); + throw new _Exception('The GD Library is not installed.'); } else { - throw new Exception(); + throw new _Exception(); } }; @@ -300,11 +302,11 @@ public function resizeImage($newWidth, $newHeight, $option = 0, $sharpen = false $option = $this->prepOption($option); // *** Make sure the file passed in is valid - if (! $this->image) { + if (!$this->image) { if ($this->debug) { - throw new Exception('file ' . $this->getFileName() . ' is missing or invalid'); + throw new _Exception('file ' . $this->getFileName() . ' is missing or invalid'); } else { - throw new Exception(); + throw new _Exception(); } }; @@ -317,7 +319,7 @@ public function resizeImage($newWidth, $newHeight, $option = 0, $sharpen = false // *** Resample - create image canvas of x, y size $this->imageResized = imagecreatetruecolor($optimalWidth, $optimalHeight); $this->keepTransparancy($optimalWidth, $optimalHeight, $this->imageResized); - imagecopyresampled($this->imageResized, $this->image, 0, 0, 0, 0, $optimalWidth, $optimalHeight, $this->width, $this->height);//phpcs:ignore + imagecopyresampled($this->imageResized, $this->image, 0, 0, 0, 0, $optimalWidth, $optimalHeight, $this->width, $this->height); //phpcs:ignore // *** If '4', then crop too @@ -358,11 +360,11 @@ public function cropImage($newWidth, $newHeight, $cropPos = 'm') { // *** Make sure the file passed in is valid - if (! $this->image) { + if (!$this->image) { if ($this->debug) { - throw new Exception('file ' . $this->getFileName() . ' is missing or invalid'); + throw new _Exception('file ' . $this->getFileName() . ' is missing or invalid'); } else { - throw new Exception(); + throw new _Exception(); } }; @@ -381,7 +383,7 @@ private function keepTransparancy($width, $height, $im) $transparent = imagecolorallocatealpha($im, 255, 255, 255, 127); imagefilledrectangle($im, 0, 0, $width, $height, $transparent); } else { - $color = imagecolorallocate($im, $this->fillColorArray['r'], $this->fillColorArray['g'], $this->fillColorArray['b']);//phpcs:ignore + $color = imagecolorallocate($im, $this->fillColorArray['r'], $this->fillColorArray['g'], $this->fillColorArray['b']); //phpcs:ignore imagefilledrectangle($im, 0, 0, $width, $height, $color); } } @@ -399,7 +401,7 @@ private function crop($optimalWidth, $optimalHeight, $newWidth, $newHeight, $cro // *** Crop this bad boy $crop = imagecreatetruecolor($newWidth, $newHeight); $this->keepTransparancy($optimalWidth, $optimalHeight, $crop); - imagecopyresampled($crop, $this->imageResized, 0, 0, $cropStartX, $cropStartY, $newWidth, $newHeight, $newWidth, $newHeight);//phpcs:ignore + imagecopyresampled($crop, $this->imageResized, 0, 0, $cropStartX, $cropStartY, $newWidth, $newHeight, $newWidth, $newHeight); //phpcs:ignore $this->imageResized = $crop; @@ -487,7 +489,7 @@ private function getCropPlacing($optimalWidth, $optimalHeight, $newWidth, $newHe } } - return array( 'x' => $cropStartX, 'y' => $cropStartY ); + return array('x' => $cropStartX, 'y' => $cropStartY); } // -------------------------------------------------------- @@ -527,7 +529,7 @@ private function getDimensions($newWidth, $newHeight, $option) break; } - return array( 'optimalWidth' => $optimalWidth, 'optimalHeight' => $optimalHeight ); + return array('optimalWidth' => $optimalWidth, 'optimalHeight' => $optimalHeight); } // -------------------------------------------------------- @@ -535,10 +537,10 @@ private function getDimensions($newWidth, $newHeight, $option) private function getSizeByFixedHeight($newWidth, $newHeight) { // *** If forcing is off... - if (! $this->forceStretch) { + if (!$this->forceStretch) { // *** ...check if actual height is less than target height if ($this->height < $newHeight) { - return array( 'optimalWidth' => $this->width, 'optimalHeight' => $this->height ); + return array('optimalWidth' => $this->width, 'optimalHeight' => $this->height); } } @@ -547,7 +549,7 @@ private function getSizeByFixedHeight($newWidth, $newHeight) $newWidth = $newHeight * $ratio; //return $newWidth; - return array( 'optimalWidth' => $newWidth, 'optimalHeight' => $newHeight ); + return array('optimalWidth' => $newWidth, 'optimalHeight' => $newHeight); } // -------------------------------------------------------- @@ -555,10 +557,10 @@ private function getSizeByFixedHeight($newWidth, $newHeight) private function getSizeByFixedWidth($newWidth, $newHeight) { // *** If forcing is off... - if (! $this->forceStretch) { + if (!$this->forceStretch) { // *** ...check if actual width is less than target width if ($this->width < $newWidth) { - return array( 'optimalWidth' => $this->width, 'optimalHeight' => $this->height ); + return array('optimalWidth' => $this->width, 'optimalHeight' => $this->height); } } @@ -567,7 +569,7 @@ private function getSizeByFixedWidth($newWidth, $newHeight) $newHeight = $newWidth * $ratio; //return $newHeight; - return array( 'optimalWidth' => $newWidth, 'optimalHeight' => $newHeight ); + return array('optimalWidth' => $newWidth, 'optimalHeight' => $newHeight); } // -------------------------------------------------------- @@ -575,10 +577,10 @@ private function getSizeByFixedWidth($newWidth, $newHeight) private function getSizeByAuto($newWidth, $newHeight) { // *** If forcing is off... - if (! $this->forceStretch) { + if (!$this->forceStretch) { // *** ...check if actual size is less than target size if ($this->width < $newWidth && $this->height < $newHeight) { - return array( 'optimalWidth' => $this->width, 'optimalHeight' => $this->height ); + return array('optimalWidth' => $this->width, 'optimalHeight' => $this->height); } } @@ -621,7 +623,7 @@ private function getSizeByAuto($newWidth, $newHeight) } } - return array( 'optimalWidth' => $optimalWidth, 'optimalHeight' => $optimalHeight ); + return array('optimalWidth' => $optimalWidth, 'optimalHeight' => $optimalHeight); } // -------------------------------------------------------- @@ -630,10 +632,10 @@ private function getOptimalCrop($newWidth, $newHeight) { // *** If forcing is off... - if (! $this->forceStretch) { + if (!$this->forceStretch) { // *** ...check if actual size is less than target size if ($this->width < $newWidth && $this->height < $newHeight) { - return array( 'optimalWidth' => $this->width, 'optimalHeight' => $this->height ); + return array('optimalWidth' => $this->width, 'optimalHeight' => $this->height); } } @@ -649,7 +651,7 @@ private function getOptimalCrop($newWidth, $newHeight) $optimalHeight = round($this->height / $optimalRatio); $optimalWidth = round($this->width / $optimalRatio); - return array( 'optimalWidth' => $optimalWidth, 'optimalHeight' => $optimalHeight ); + return array('optimalWidth' => $optimalWidth, 'optimalHeight' => $optimalHeight); } // -------------------------------------------------------- @@ -660,9 +662,11 @@ private function sharpen() if (version_compare(PHP_VERSION, '5.1.0') >= 0) { // *** if ($this->aggresiveSharpening) { // A more aggressive sharpening solution - $sharpenMatrix = array( array( -1, -1, -1 ), - array( -1, 16, -1 ), - array( -1, -1, -1 ) ); + $sharpenMatrix = array( + array(-1, -1, -1), + array(-1, 16, -1), + array(-1, -1, -1) + ); $divisor = 8; $offset = 0; @@ -672,10 +676,10 @@ private function sharpen() $sharpness = $this->findSharp($this->widthOriginal, $this->width); $sharpenMatrix = array( - array( -1, -2, -1 ), + array(-1, -2, -1), //Lessen the effect of a filter by increasing the value in the center cell - array( -2, $sharpness + 12, -2 ), - array( -1, -2, -1 ) + array(-2, $sharpness + 12, -2), + array(-1, -2, -1) ); $divisor = $sharpness; // adjusts brightness $offset = 0; @@ -683,7 +687,7 @@ private function sharpen() } } else { if ($this->debug) { - throw new Exception('Sharpening required PHP 5.1.0 or greater.'); + throw new _Exception('Sharpening required PHP 5.1.0 or greater.'); } } } @@ -693,10 +697,10 @@ private function sharpen() private function sharpen2($level) { $sharpenMatrix = array( - array( $level, $level, $level ), + array($level, $level, $level), //Lessen the effect of a filter by increasing the value in the center cell - array( $level, (8 * $level) + 1, $level ), - array( $level, $level, $level ) + array($level, (8 * $level) + 1, $level), + array($level, $level, $level) ); } @@ -722,7 +726,7 @@ private function prepOption($option) if (RFM::fixStrtolower($option[0]) == 'crop' && count($option) == 2) { return 'crop'; } else { - throw new Exception('Crop resize option array is badly formatted.'); + throw new _Exception('Crop resize option array is badly formatted.'); } } else { if (strpos($option, 'crop') !== false) { @@ -768,7 +772,7 @@ public function borderPreset($preset) Draw border *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*/ - public function addBorder($thickness = 1, $rgbArray = array( 255, 255, 255 )) + public function addBorder($thickness = 1, $rgbArray = array(255, 255, 255)) { if ($this->imageResized) { $rgbArray = $this->formatColor($rgbArray); @@ -986,7 +990,7 @@ public function imageColorize($rgb) Reflection *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*/ - public function addReflection($reflectionHeight = 50, $startingTransparency = 30, $inside = false, $bgColor = '#fff', $stretch = false, $divider = 0)//phpcs:ignore + public function addReflection($reflectionHeight = 50, $startingTransparency = 30, $inside = false, $bgColor = '#fff', $stretch = false, $divider = 0) //phpcs:ignore { // *** Convert color @@ -1050,7 +1054,7 @@ public function addReflection($reflectionHeight = 50, $startingTransparency = 30 // Create new blank image with sizes. $final = imagecreatetruecolor($this->width, $this->height); - imagecopymerge($final, $this->imageResized, 0, 0, 0, $reflectionHeight, $this->width, $this->height - $reflectionHeight, 100);//phpcs:ignore + imagecopymerge($final, $this->imageResized, 0, 0, 0, $reflectionHeight, $this->width, $this->height - $reflectionHeight, 100); //phpcs:ignore imagecopymerge($final, $im, 0, $this->height - $reflectionHeight, 0, 0, $x, $y, 100); } else { // Create new blank image with sizes. @@ -1134,7 +1138,7 @@ public function roundCorners($radius = 5, $bgColor = 'transparent') // *** Check if the user wants transparency $isTransparent = false; - if (! is_array($bgColor)) { + if (!is_array($bgColor)) { if (RFM::fixStrtolower($bgColor) == 'transparent') { $isTransparent = true; } @@ -1258,10 +1262,10 @@ public function addShadow($shadowAngle = 45, $blur = 15, $bgColor = 'transparent $colour = imagecolorallocate($rgb, 255, 255, 255); //imagefilledrectangle($rgb, $blurWidth*0.5-$distWidth, $blurHeight*0.5-$distHeight, // $width+$blurWidth*0.5-$distWidth, $height+$blurWidth*0.5-$distHeight, $colour); - imagefilledrectangle($rgb, $blurWidth * 0.5 - $distWidth, $blurHeight * 0.5 - $distHeight, $width + $blurWidth * 0.5 - $distWidth, $height + $blurWidth * 0.5 - $distHeight, $colour);//phpcs:ignore + imagefilledrectangle($rgb, $blurWidth * 0.5 - $distWidth, $blurHeight * 0.5 - $distHeight, $width + $blurWidth * 0.5 - $distWidth, $height + $blurWidth * 0.5 - $distHeight, $colour); //phpcs:ignore //imagecopymerge($rgb, $newImage, 1+$blurWidth*0.5-$distWidth, 1+$blurHeight*0.5-$distHeight, // 0,0, $width, $height, 100); - imagecopymerge($rgb, $newImage, $blurWidth * 0.5 - $distWidth, $blurHeight * 0.5 - $distHeight, 0, 0, $width + $blurWidth, $height + $blurHeight, 100);//phpcs:ignore + imagecopymerge($rgb, $newImage, $blurWidth * 0.5 - $distWidth, $blurHeight * 0.5 - $distHeight, 0, 0, $width + $blurWidth, $height + $blurHeight, 100); //phpcs:ignore // *** Shadow (alpha) @@ -1293,17 +1297,17 @@ public function addShadow($shadowAngle = 45, $blur = 15, $bgColor = 'transparent $t = ((1.0 * $i) / STEPS); $intensity = 255 * $t * $t; - $colour = imagecolorallocate($shadow, $intensity, $intensity, $intensity);//phpcs:ignore - imagefilledarc($shadow, $blurWidth - 1, $blurHeight - 1, 2 * (1 - $t) * $blurWidth, 2 * (1 - $t) * $blurHeight, 180, 268, $colour, IMG_ARC_PIE);//phpcs:ignore - imagefilledarc($shadow, $width, $blurHeight - 1, 2 * (1 - $t) * $blurWidth, 2 * (1 - $t) * $blurHeight, 270, 358, $colour, IMG_ARC_PIE);//phpcs:ignore - imagefilledarc($shadow, $width, $height, 2 * (1 - $t) * $blurWidth, 2 * (1 - $t) * $blurHeight, 0, 90, $colour, IMG_ARC_PIE);//phpcs:ignore - imagefilledarc($shadow, $blurWidth - 1, $height, 2 * (1 - $t) * $blurWidth, 2 * (1 - $t) * $blurHeight, 90, 180, $colour, IMG_ARC_PIE);//phpcs:ignore + $colour = imagecolorallocate($shadow, $intensity, $intensity, $intensity); //phpcs:ignore + imagefilledarc($shadow, $blurWidth - 1, $blurHeight - 1, 2 * (1 - $t) * $blurWidth, 2 * (1 - $t) * $blurHeight, 180, 268, $colour, IMG_ARC_PIE); //phpcs:ignore + imagefilledarc($shadow, $width, $blurHeight - 1, 2 * (1 - $t) * $blurWidth, 2 * (1 - $t) * $blurHeight, 270, 358, $colour, IMG_ARC_PIE); //phpcs:ignore + imagefilledarc($shadow, $width, $height, 2 * (1 - $t) * $blurWidth, 2 * (1 - $t) * $blurHeight, 0, 90, $colour, IMG_ARC_PIE); //phpcs:ignore + imagefilledarc($shadow, $blurWidth - 1, $height, 2 * (1 - $t) * $blurWidth, 2 * (1 - $t) * $blurHeight, 90, 180, $colour, IMG_ARC_PIE); //phpcs:ignore } $colour = imagecolorallocate($shadow, 255, 255, 255); imagefilledrectangle($shadow, $blurWidth, $blurHeight, $width, $height, $colour); - imagefilledrectangle($shadow, $blurWidth * 0.5 - $distWidth, $blurHeight * 0.5 - $distHeight, $width + $blurWidth * 0.5 - 1 - $distWidth, $height + $blurHeight * 0.5 - 1 - $distHeight, $colour);//phpcs:ignore + imagefilledrectangle($shadow, $blurWidth * 0.5 - $distWidth, $blurHeight * 0.5 - $distHeight, $width + $blurWidth * 0.5 - 1 - $distWidth, $height + $blurHeight * 0.5 - 1 - $distHeight, $colour); //phpcs:ignore // *** The magic @@ -1327,7 +1331,7 @@ public function addShadow($shadowAngle = 45, $blur = 15, $bgColor = 'transparent if (RFM::fixStrtolower($bgColor) == 'transparent') { $myColour = imagecolorallocatealpha($rgb, $r, $g, $b, $a); } else { - $myColour = imagecolorallocate($rgb, $r * (1.0 - $t) + $r0 * $t, $g * (1.0 - $t) + $g0 * $t, $b * (1.0 - $t) + $b0 * $t);//phpcs:ignore + $myColour = imagecolorallocate($rgb, $r * (1.0 - $t) + $r0 * $t, $g * (1.0 - $t) + $g0 * $t, $b * (1.0 - $t) + $b0 * $t); //phpcs:ignore } // *** Add color to new rgb image @@ -1350,7 +1354,7 @@ public function addShadow($shadowAngle = 45, $blur = 15, $bgColor = 'transparent Add Caption Box *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*/ - public function addCaptionBox($side = 'b', $thickness = 50, $padding = 0, $bgColor = '#000', $transaprencyAmount = 30)//phpcs:ignore + public function addCaptionBox($side = 'b', $thickness = 50, $padding = 0, $bgColor = '#000', $transaprencyAmount = 30) //phpcs:ignore { $side = RFM::fixStrtolower($side); @@ -1367,8 +1371,8 @@ public function addCaptionBox($side = 'b', $thickness = 50, $padding = 0, $bgCol $transaprencyAmount = $this->invertTransparency($transaprencyAmount, 127, false); - $transparent = imagecolorallocatealpha($this->imageResized, $r, $g, $b, $transaprencyAmount);//phpcs:ignore - imagefilledrectangle($this->imageResized, $positionArray['x1'], $positionArray['y1'], $positionArray['x2'], $positionArray['y2'], $transparent);//phpcs:ignore + $transparent = imagecolorallocatealpha($this->imageResized, $r, $g, $b, $transaprencyAmount); //phpcs:ignore + imagefilledrectangle($this->imageResized, $positionArray['x1'], $positionArray['y1'], $positionArray['x2'], $positionArray['y2'], $transparent); //phpcs:ignore } // -------------------------------------------------------- @@ -1384,7 +1388,7 @@ public function addTextToCaptionBox($text, $fontColor = '#fff', $fontSize = 12, $y2 = $this->captionBoxPositionArray['y2']; } else { if ($this->debug) { - throw new Exception('No caption box found.'); + throw new _Exception('No caption box found.'); } else { return false; } @@ -1458,28 +1462,28 @@ private function calculateCaptionBoxPosition($side, $thickness, $padding) public function getExif($debug = false) { - if (! $this->debug || ! $debug) { + if (!$this->debug || !$debug) { $debug = false; } // *** Check all is good - check the EXIF library exists and the file exists, too. - if (! $this->testEXIFInstalled()) { + if (!$this->testEXIFInstalled()) { if ($debug) { - throw new Exception('The EXIF Library is not installed.'); + throw new _Exception('The EXIF Library is not installed.'); } else { return array(); } }; - if (! file_exists($this->fileName)) { + if (!file_exists($this->fileName)) { if ($debug) { - throw new Exception('Image not found.'); + throw new _Exception('Image not found.'); } else { return array(); } }; if ($this->fileExtension != '.jpg') { if ($debug) { - throw new Exception('Metadata not supported for this image type.'); + throw new _Exception('Metadata not supported for this image type.'); } else { return array(); } @@ -1828,17 +1832,17 @@ private function iptcMaketag($rec, $dat, $val) $len = strlen($val); if ($len < 0x8000) { return chr(0x1c) . chr($rec) . chr($dat) . - chr($len >> 8) . - chr($len & 0xff) . - $val; + chr($len >> 8) . + chr($len & 0xff) . + $val; } else { return chr(0x1c) . chr($rec) . chr($dat) . - chr(0x80) . chr(0x04) . - chr(($len >> 24) & 0xff) . - chr(($len >> 16) & 0xff) . - chr(($len >> 8) & 0xff) . - chr(($len) & 0xff) . - $val; + chr(0x80) . chr(0x04) . + chr(($len >> 24) & 0xff) . + chr(($len >> 16) & 0xff) . + chr(($len >> 8) & 0xff) . + chr(($len) & 0xff) . + $val; } } @@ -1855,7 +1859,7 @@ private function iptcMaketag($rec, $dat, $val) Add Text *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*/ - public function addText($text, $pos = '20x20', $padding = 0, $fontColor = '#fff', $fontSize = 12, $angle = 0, $font = null)//phpcs:ignore + public function addText($text, $pos = '20x20', $padding = 0, $fontColor = '#fff', $fontSize = 12, $angle = 0, $font = null) //phpcs:ignore { // *** Convert color @@ -1895,15 +1899,15 @@ private function getTextFont($font) putenv('GDFONTPATH=' . realpath('.')); // *** Check if the passed in font exsits... - if ($font == null || ! file_exists($font)) { + if ($font == null || !file_exists($font)) { // *** ...If not, default to this font. $font = $fontPath . '/arimo.ttf'; // *** Check our default font exists... - if (! file_exists($font)) { + if (!file_exists($font)) { // *** If not, return false if ($this->debug) { - throw new Exception('Font not found'); + throw new _Exception('Font not found'); } else { return false; } @@ -1927,7 +1931,7 @@ private function getTextSize($fontSize, $angle, $font, $text) // *** Get height of text from dimensions (should also be same as $fontSize) $textHeight = abs($box[5] - $box[1]); - return array( 'height' => $textHeight, 'width' => $textWidth ); + return array('height' => $textHeight, 'width' => $textWidth); } @@ -1987,8 +1991,7 @@ private function calculatePosition($pos, $padding, $assetWidth, $assetHeight, $u case 'tr': $width = $this->width - $assetWidth - $padding; - $height = 0 + $padding; - ; + $height = 0 + $padding;; break; case 'l': @@ -2028,11 +2031,11 @@ private function calculatePosition($pos, $padding, $assetWidth, $assetHeight, $u } } - if (! $upperLeft) { + if (!$upperLeft) { $height = $height + $assetHeight; } - return array( 'width' => $width, 'height' => $height ); + return array('width' => $width, 'height' => $height); } @@ -2041,7 +2044,7 @@ private function calculatePosition($pos, $padding, $assetWidth, $assetHeight, $u private function filterOpacity(&$img, $opacity = 75) { - if (! isset($opacity)) { + if (!isset($opacity)) { return false; } @@ -2082,9 +2085,9 @@ private function filterOpacity(&$img, $opacity = 75) $alpha += 127 * $opacity; } //get the color index with new alpha - $alphacolorxy = imagecolorallocatealpha($img, ($colorxy >> 16) & 0xFF, ($colorxy >> 8) & 0xFF, $colorxy & 0xFF, $alpha);//phpcs:ignore + $alphacolorxy = imagecolorallocatealpha($img, ($colorxy >> 16) & 0xFF, ($colorxy >> 8) & 0xFF, $colorxy & 0xFF, $alpha); //phpcs:ignore //set pixel with the new color + opacity - if (! imagesetpixel($img, $x, $y, $alphacolorxy)) { + if (!imagesetpixel($img, $x, $y, $alphacolorxy)) { return false; } } @@ -2098,11 +2101,11 @@ private function filterOpacity(&$img, $opacity = 75) private function openImage($file) { - if (! file_exists($file) && ! $this->checkStringStartsWith('http://', $file) && ! $this->checkStringStartsWith('https://', $file)) {//phpcs:ignore + if (!file_exists($file) && !$this->checkStringStartsWith('http://', $file) && !$this->checkStringStartsWith('https://', $file)) { //phpcs:ignore if ($this->debug) { - throw new Exception('Image not found.'); + throw new _Exception('Image not found.'); } else { - throw new Exception(); + throw new _Exception(); } }; @@ -2130,7 +2133,7 @@ private function openImage($file) break; - // ... etc + // ... etc default: $img = false; @@ -2153,20 +2156,20 @@ public function saveImage($savePath, $imageQuality = "100") { // *** Perform a check or two. - if (! is_resource($this->imageResized)) { + if (!is_resource($this->imageResized)) { if ($this->debug) { - throw new Exception('saveImage: This is not a resource.'); + throw new _Exception('saveImage: This is not a resource.'); } else { - throw new Exception(); + throw new _Exception(); } } $fileInfoArray = pathInfo($savePath); clearstatcache(); - if (! is_writable($fileInfoArray['dirname'])) { + if (!is_writable($fileInfoArray['dirname'])) { if ($this->debug) { - throw new Exception('The path is not writable. Please check your permissions.'); + throw new _Exception('The path is not writable. Please check your permissions.'); } else { - throw new Exception(); + throw new _Exception(); } } @@ -2216,7 +2219,7 @@ public function saveImage($savePath, $imageQuality = "100") break; - // ... etc + // ... etc default: // *** No extension - No save. @@ -2237,11 +2240,11 @@ public function saveImage($savePath, $imageQuality = "100") public function displayImage($fileType = 'jpg', $imageQuality = "100") { - if (! is_resource($this->imageResized)) { + if (!is_resource($this->imageResized)) { if ($this->debug) { - throw new Exception('saveImage: This is not a resource.'); + throw new _Exception('saveImage: This is not a resource.'); } else { - throw new Exception(); + throw new _Exception(); } } @@ -2270,7 +2273,7 @@ public function displayImage($fileType = 'jpg', $imageQuality = "100") echo 'bmp file format is not supported.'; break; - // ... etc + // ... etc default: // *** No extension - No save. @@ -2499,15 +2502,15 @@ private function findUnusedGreen() $green = 255; do { - $greenChroma = array( 0, $green, 0 ); + $greenChroma = array(0, $green, 0); $colorArray = $this->formatColor($greenChroma); $match = $this->testColorExists($colorArray); $green--; } while ($match == false && $green > 0); // *** If no match, just bite the bullet and use green value of 255 - if (! $match) { - $greenChroma = array( 0, $green, 0 ); + if (!$match) { + $greenChroma = array(0, $green, 0); } return $greenChroma; @@ -2520,15 +2523,15 @@ private function findUnusedBlue() $blue = 255; do { - $blueChroma = array( 0, 0, $blue ); + $blueChroma = array(0, 0, $blue); $colorArray = $this->formatColor($blueChroma); $match = $this->testColorExists($colorArray); $blue--; } while ($match == false && $blue > 0); // *** If no match, just bite the bullet and use blue value of 255 - if (! $match) { - $blueChroma = array( 0, 0, $blue ); + if (!$match) { + $blueChroma = array(0, 0, $blue); } return $blueChroma; @@ -2641,7 +2644,7 @@ private function GD2BMPstring(&$gd_image) private function getPixelColor(&$img, $x, $y) { - if (! is_resource($img)) { + if (!is_resource($img)) { return false; } @@ -2670,7 +2673,7 @@ private function imageCreateFromBMP($filename) { //Ouverture du fichier en mode binaire - if (! $f1 = fopen($filename, "rb")) { + if (!$f1 = fopen($filename, "rb")) { return false; } @@ -2683,8 +2686,8 @@ private function imageCreateFromBMP($filename) //2 : Chargement des ent�tes BMP $BMP = unpack( 'Vheader_size/Vwidth/Vheight/vplanes/vbits_per_pixel' . - '/Vcompression/Vsize_bitmap/Vhoriz_resolution' . - '/Vvert_resolution/Vcolors_used/Vcolors_important', + '/Vcompression/Vsize_bitmap/Vhoriz_resolution' . + '/Vvert_resolution/Vcolors_used/Vcolors_important', fread($f1, 40) ); $BMP['colors'] = pow(2, $BMP['bits_per_pixel']); @@ -2745,7 +2748,7 @@ private function imageCreateFromBMP($filename) $COLOR[1] = $red * 65536 + $green * 256 + $blue; } elseif ($BMP['bits_per_pixel'] == 8) { $COLOR = unpack("n", $VIDE . substr($IMG, $P, 1)); - $COLOR[1] = $PALETTE[ $COLOR[1] + 1 ]; + $COLOR[1] = $PALETTE[$COLOR[1] + 1]; } elseif ($BMP['bits_per_pixel'] == 4) { $COLOR = unpack("n", $VIDE . substr($IMG, floor($P), 1)); if (($P * 2) % 2 == 0) { @@ -2753,7 +2756,7 @@ private function imageCreateFromBMP($filename) } else { $COLOR[1] = ($COLOR[1] & 0x0F); } - $COLOR[1] = $PALETTE[ $COLOR[1] + 1 ]; + $COLOR[1] = $PALETTE[$COLOR[1] + 1]; } elseif ($BMP['bits_per_pixel'] == 1) { $COLOR = unpack("n", $VIDE . substr($IMG, floor($P), 1)); if (($P * 8) % 8 == 0) { @@ -2773,7 +2776,7 @@ private function imageCreateFromBMP($filename) } elseif (($P * 8) % 8 == 7) { $COLOR[1] = ($COLOR[1] & 0x1); } - $COLOR[1] = $PALETTE[ $COLOR[1] + 1 ]; + $COLOR[1] = $PALETTE[$COLOR[1] + 1]; } else { return false; } diff --git a/src/ResponsiveFileManager/UploadHandler.php b/src/ResponsiveFileManager/UploadHandler.php index 28595c4..525e6f7 100755 --- a/src/ResponsiveFileManager/UploadHandler.php +++ b/src/ResponsiveFileManager/UploadHandler.php @@ -1,4 +1,5 @@ getUploadPath($file_name); - if (is_file($file_path) && $file_name[0] !== '.') { + if (strlen($file_name) > 0 && $file_name[0] !== '.' && is_file($file_path)) { return true; } return false; @@ -422,7 +418,11 @@ public function getConfigBytes($val) { $val = trim($val); $last = strtolower($val[strlen($val) - 1]); - $val = (int) $val; + if (is_numeric($val)) { + $val = (int) $val; + } else { + $val = (int) substr($val, 0, -1); + } switch ($last) { case 'g': $val *= 1024; @@ -459,19 +459,22 @@ protected function validate($uploaded_file, $file, $error, $index) } else { $file_size = $content_length; } - if ($this->options['max_file_size'] && ($file_size > $this->options['max_file_size'] || + if ( + $this->options['max_file_size'] && ($file_size > $this->options['max_file_size'] || $file->size > $this->options['max_file_size']) ) { $file->error = $this->getErrorMessage('max_file_size'); return false; } - if ($this->options['min_file_size'] && + if ( + $this->options['min_file_size'] && $file_size < $this->options['min_file_size'] ) { $file->error = $this->getErrorMessage('min_file_size'); return false; } - if (is_int($this->options['max_number_of_files']) && + if ( + is_int($this->options['max_number_of_files']) && ($this->countFileObjects() >= $this->options['max_number_of_files']) && // Ignore additional chunks of existing files: !is_file($this->getUploadPath($file->name)) @@ -489,7 +492,8 @@ protected function validate($uploaded_file, $file, $error, $index) list($img_width, $img_height) = $this->getImageSize($uploaded_file); // If we are auto rotating the image by default, do the checks on // the correct orientation - if (@$this->options['image_versions']['']['auto_orient'] && + if ( + @$this->options['image_versions']['']['auto_orient'] && function_exists('exif_read_data') && ($exif = @exif_read_data($uploaded_file)) && (((int) @$exif['Orientation']) >= 5) ) { @@ -550,7 +554,7 @@ protected function getUniqueFilename( $name = $this->upcountName($name); } // Keep an existing filename if this is part of a chunked upload: - $uploaded_bytes = $this->fixIntegerOverflow((int) $content_range[1]); + $uploaded_bytes = $this->fixIntegerOverflow((int) @$content_range[1]); while (is_file($this->getUploadPath($name))) { if ($uploaded_bytes === $this->getFileSize( $this->getUploadPath($name) @@ -572,7 +576,8 @@ protected function fixFileExtension( $content_range ) { // Add missing file extension for known image types: - if (strpos($name, '.') === false && + if ( + strpos($name, '.') === false && preg_match('/^image\/(gif|jpe?g|png)/', $type, $matches) ) { $name .= '.' . $matches[1]; @@ -1023,7 +1028,8 @@ protected function imagickCreateScaledImage($file_name, $version, $options) $image_strip = (isset($options['strip']) ? $options['strip'] : false); - if (!$image_oriented && + if ( + !$image_oriented && ($max_width >= $img_width) && ($max_height >= $img_height) && !$image_strip && @@ -1232,7 +1238,7 @@ protected function handleImageFile($file_path, $file) } if (count($failed_versions)) { $file->error = $this->getErrorMessage('image_resize') - . ' (' . implode($failed_versions, [', ']) . ')'; + . ' (' . implode(', ', $failed_versions) . ')'; } // Free memory: $this->destroyImageObject($file_path); @@ -1542,7 +1548,7 @@ public function post($ftp, $print_response = true) $content_range_header = $this->getServerVar('HTTP_CONTENT_RANGE'); $content_range = $content_range_header ? preg_split('/[^0-9]+/', $content_range_header) : null; - $size = $content_range ? $content_range[3] : null; + $size = @$content_range[3]; $files = array(); if ($upload) { if (is_array($upload['tmp_name'])) { @@ -1580,7 +1586,7 @@ public function post($ftp, $print_response = true) $name = $file_name ? $file_name : $upload['name'][0]; $res = $this->generateResponse($response, $print_response); if (is_file($this->getUploadPath($name))) { - $uploaded_bytes = $this->fixIntegerOverflow((int) $content_range[1]); + $uploaded_bytes = $this->fixIntegerOverflow((int) @$content_range[1]); $totalSize = $this->getFileSize($this->getUploadPath($name)); if ($totalSize - $uploaded_bytes - $this->options['readfile_chunk_size'] < 0) { $this->onUploadEnd($ftp, $res); @@ -1645,7 +1651,8 @@ public function onUploadEnd($ftp, $res) $res['files'][0]->error = $thumbResult; } } else { - if (!$this->options['ftp'] && + if ( + !$this->options['ftp'] && !RFM::newThumbnailsCreation( $ftp, $targetPath, @@ -1668,10 +1675,10 @@ public function onUploadEnd($ftp, $res) $this->options['config']['image_resizing_width'] = $srcWidth; $this->options['config']['image_resizing_height'] = $srcHeight; } else { - $this->options['config']['image_resizing_width'] = $this->options['config']['image_resizing_height'] * $srcWidth / $srcHeight;//phpcs:ignore + $this->options['config']['image_resizing_width'] = $this->options['config']['image_resizing_height'] * $srcWidth / $srcHeight; //phpcs:ignore } } elseif ($this->options['config']['image_resizing_height'] == 0) { // if height not set - $this->options['config']['image_resizing_height'] = $this->options['config']['image_resizing_width'] * $srcHeight / $srcWidth;//phpcs:ignore + $this->options['config']['image_resizing_height'] = $this->options['config']['image_resizing_width'] * $srcHeight / $srcWidth; //phpcs:ignore } // new dims and create @@ -1688,9 +1695,11 @@ public function onUploadEnd($ftp, $res) //max resizing limit control $resize = false; - if ($this->options['config']['image_max_width'] != 0 && + if ( + $this->options['config']['image_max_width'] != 0 && $srcWidth > $this->options['config']['image_max_width'] && - $this->options['config']['image_resizing_override'] === false) { + $this->options['config']['image_resizing_override'] === false + ) { $resize = true; $srcWidth = $this->options['config']['image_max_width']; @@ -1699,9 +1708,11 @@ public function onUploadEnd($ftp, $res) } } - if ($this->options['config']['image_max_height'] != 0 && + if ( + $this->options['config']['image_max_height'] != 0 && $srcHeight > $this->options['config']['image_max_height'] && - $this->options['config']['image_resizing_override'] === false) { + $this->options['config']['image_resizing_override'] === false + ) { $resize = true; $srcHeight = $this->options['config']['image_max_height']; @@ -1744,7 +1755,7 @@ public function delete($print_response = true) $response = array(); foreach ($file_names as $file_name) { $file_path = $this->getUploadPath($file_name); - $success = is_file($file_path) && $file_name[0] !== '.' && unlink($file_path); + $success = strlen($file_name) > 0 && $file_name[0] !== '.' && is_file($file_path) && unlink($file_path); if ($success) { foreach ($this->options['image_versions'] as $version => $options) { if (!empty($version)) {