aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/legacy
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2018-01-13 00:34:28 +0100
committerMorris Jobke <hey@morrisjobke.de>2018-01-17 10:00:33 +0100
commite4b3ee8d8f93262423eaaeee390deb6e680bb1e3 (patch)
tree3c24e04be9a760d73490fdc75f9ae788051eb886 /lib/private/legacy
parent16f4d71efd257e66550d61013e39ecf96c10fa0f (diff)
downloadnextcloud-server-e4b3ee8d8f93262423eaaeee390deb6e680bb1e3.tar.gz
nextcloud-server-e4b3ee8d8f93262423eaaeee390deb6e680bb1e3.zip
Fix float/integer handling in image API
* IImage::crop/preciseResize now have type hinting for integers * found while testing strict typing for PHP 7+ Signed-off-by: Morris Jobke <hey@morrisjobke.de>
Diffstat (limited to 'lib/private/legacy')
-rw-r--r--lib/private/legacy/image.php18
1 files changed, 14 insertions, 4 deletions
diff --git a/lib/private/legacy/image.php b/lib/private/legacy/image.php
index a0159b927f9..873f9711d5c 100644
--- a/lib/private/legacy/image.php
+++ b/lib/private/legacy/image.php
@@ -550,6 +550,16 @@ class OC_Image implements \OCP\IImage {
* @return bool|resource An image resource or false on error
*/
public function loadFromFile($imagePath = false) {
+ try {
+ // detect if it is a path or maybe the images as string
+ // needed because the constructor iterates over all load* methods
+ $result = @realpath($imagePath);
+ if ($result === false) {
+ return false;
+ }
+ } catch (Error $e) {
+ return false;
+ }
// exif_imagetype throws "read error!" if file is less than 12 byte
if (!@is_file($imagePath) || !file_exists($imagePath) || filesize($imagePath) < 12 || !is_readable($imagePath)) {
return false;
@@ -873,7 +883,7 @@ class OC_Image implements \OCP\IImage {
$newHeight = $maxSize;
}
- $this->preciseResize(round($newWidth), round($newHeight));
+ $this->preciseResize((int)round($newWidth), (int)round($newHeight));
return true;
}
@@ -882,7 +892,7 @@ class OC_Image implements \OCP\IImage {
* @param int $height
* @return bool
*/
- public function preciseResize($width, $height) {
+ public function preciseResize(int $width, int $height): bool {
if (!$this->valid()) {
$this->logger->error(__METHOD__ . '(): No image loaded', array('app' => 'core'));
return false;
@@ -982,7 +992,7 @@ class OC_Image implements \OCP\IImage {
* @param int $h Height
* @return bool for success or failure
*/
- public function crop($x, $y, $w, $h) {
+ public function crop(int $x, int $y, int $w, int $h): bool {
if (!$this->valid()) {
$this->logger->error(__METHOD__ . '(): No image loaded', array('app' => 'core'));
return false;
@@ -1033,7 +1043,7 @@ class OC_Image implements \OCP\IImage {
$newWidth = min($maxWidth, $ratio * $maxHeight);
$newHeight = min($maxHeight, $maxWidth / $ratio);
- $this->preciseResize(round($newWidth), round($newHeight));
+ $this->preciseResize((int)round($newWidth), (int)round($newHeight));
return true;
}