-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
98e0eeb
commit 07aa0f0
Showing
10 changed files
with
129 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -106,11 +106,10 @@ public function __construct($imageRef = null, $logger = null, $config = null) { | |
|
||
/** | ||
* Determine whether the object contains an image resource. | ||
* | ||
* @return bool | ||
*/ | ||
public function valid() { // apparently you can't name a method 'empty'... | ||
return \is_resource($this->resource); | ||
public function valid(): bool { | ||
// apparently you can't name a method 'empty'... | ||
return $this->resource instanceof \GdImage; | ||
} | ||
|
||
/** | ||
|
@@ -217,7 +216,9 @@ public function save($filePath = null, $mimeType = null) { | |
if ($filePath === null && $this->filePath === null) { | ||
$this->logger->error(__METHOD__ . '(): called with no path.', ['app' => 'core']); | ||
return false; | ||
} elseif ($filePath === null && $this->filePath !== null) { | ||
} | ||
|
||
if ($filePath === null && $this->filePath !== null) { | ||
$filePath = $this->filePath; | ||
} | ||
return $this->_output($filePath, $mimeType); | ||
|
@@ -239,7 +240,9 @@ private function _output($filePath = null, $mimeType = null) { | |
if (!\is_writable(\dirname($filePath))) { | ||
$this->logger->error(__METHOD__ . '(): Directory \'' . \dirname($filePath) . '\' is not writable.', ['app' => 'core']); | ||
return false; | ||
} elseif (\is_writable(\dirname($filePath)) && \file_exists($filePath) && !\is_writable($filePath)) { | ||
} | ||
|
||
if (\is_writable(\dirname($filePath)) && \file_exists($filePath) && !\is_writable($filePath)) { | ||
$this->logger->error(__METHOD__ . '(): File \'' . $filePath . '\' is not writable.', ['app' => 'core']); | ||
return false; | ||
} | ||
|
@@ -315,10 +318,7 @@ public function __invoke() { | |
return $this->show(); | ||
} | ||
|
||
/** | ||
* @return resource Returns the image resource in any. | ||
*/ | ||
public function resource() { | ||
public function resource(): ?GdImage { | ||
return $this->resource; | ||
} | ||
|
||
|
@@ -490,18 +490,18 @@ public function fixOrientation() { | |
\imagedestroy($this->resource); | ||
$this->resource = $res; | ||
return true; | ||
} else { | ||
$this->logger->debug('OC_Image->fixOrientation() Error during alpha-saving', ['app' => 'core']); | ||
return false; | ||
} | ||
} else { | ||
$this->logger->debug('OC_Image->fixOrientation() Error during alpha-blending', ['app' => 'core']); | ||
|
||
$this->logger->debug('OC_Image->fixOrientation() Error during alpha-saving', ['app' => 'core']); | ||
return false; | ||
} | ||
} else { | ||
$this->logger->debug('OC_Image->fixOrientation() Error during orientation fixing', ['app' => 'core']); | ||
|
||
$this->logger->debug('OC_Image->fixOrientation() Error during alpha-blending', ['app' => 'core']); | ||
return false; | ||
} | ||
|
||
$this->logger->debug('OC_Image->fixOrientation() Error during orientation fixing', ['app' => 'core']); | ||
return false; | ||
} | ||
return false; | ||
} | ||
|
@@ -541,9 +541,9 @@ public function load(\GdImage|string $imageRef) { | |
* It is the responsibility of the caller to position the pointer at the correct place and to close the handle again. | ||
* | ||
* @param resource $handle | ||
* @return resource|false An image resource or false on error | ||
* @return GdImage|false|null An image resource or false on error | ||
*/ | ||
public function loadFromFileHandle($handle) { | ||
public function loadFromFileHandle($handle): GdImage|false|null { | ||
$contents = \stream_get_contents($handle); | ||
if ($this->loadFromData($contents)) { | ||
$this->adjustStreamChunkSize($handle); | ||
|
@@ -671,7 +671,10 @@ public function loadFromFile($imagePath = false) { | |
} | ||
break; | ||
case IMAGETYPE_BMP: | ||
$this->resource = $this->imagecreatefrombmp($imagePath); | ||
$resource = $this->imagecreatefrombmp($imagePath); | ||
if ($resource !== false) { | ||
$this->resource = $resource; | ||
} | ||
break; | ||
/* | ||
case IMAGETYPE_TIFF_II: // (intel byte order) | ||
|
@@ -718,52 +721,52 @@ public function loadFromFile($imagePath = false) { | |
* Loads an image from a string of data. | ||
* | ||
* @param string $str A string of image data as read from a file. | ||
* @return bool|resource An image resource or false on error | ||
* @return bool An image resource or false on error | ||
*/ | ||
public function loadFromData($str) { | ||
if (\is_resource($str)) { | ||
if (!\is_string($str)) { | ||
return false; | ||
} | ||
$this->resource = @\imagecreatefromstring($str); | ||
$resource = @\imagecreatefromstring($str); | ||
if ($this->fileInfo) { | ||
$this->mimeType = $this->fileInfo->buffer($str); | ||
} | ||
if (\is_resource($this->resource)) { | ||
\imagealphablending($this->resource, false); | ||
\imagesavealpha($this->resource, true); | ||
} | ||
|
||
if (!$this->resource) { | ||
if (!$resource) { | ||
$this->logger->debug('OC_Image->loadFromFile, could not load', ['app' => 'core']); | ||
return false; | ||
} | ||
return $this->resource; | ||
$this->resource = $resource; | ||
\imagealphablending($this->resource, false); | ||
\imagesavealpha($this->resource, true); | ||
|
||
return true; | ||
} | ||
|
||
/** | ||
* Loads an image from a base64 encoded string. | ||
* | ||
* @param string $str A string base64 encoded string of image data. | ||
* @return bool|resource An image resource or false on error | ||
* @return bool An image resource or false on error | ||
*/ | ||
public function loadFromBase64($str) { | ||
private function loadFromBase64($str) { | ||
if (!\is_string($str)) { | ||
return false; | ||
} | ||
$data = \base64_decode($str); | ||
if ($data) { // try to load from string data | ||
$this->resource = @\imagecreatefromstring($data); | ||
$resource = @\imagecreatefromstring($data); | ||
if ($this->fileInfo) { | ||
$this->mimeType = $this->fileInfo->buffer($data); | ||
} | ||
if (!$this->resource) { | ||
if ($resource === false) { | ||
$this->logger->debug('OC_Image->loadFromBase64, could not load', ['app' => 'core']); | ||
return false; | ||
} | ||
return $this->resource; | ||
} else { | ||
return false; | ||
$this->resource = $resource; | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
/** | ||
|
@@ -1019,7 +1022,7 @@ public function __destruct() { | |
* @link http://www.programmierer-forum.de/imagebmp-gute-funktion-gefunden-t143716.htm | ||
* @author mgutt <[email protected]> | ||
* @version 1.00 | ||
* @param resource $im | ||
* @param \GdImage $im | ||
* @param string $fileName [optional] <p>The path to save the file to.</p> | ||
* @param int $bit [optional] <p>Bit depth, (default is 24).</p> | ||
* @param int $compression [optional] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.