]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - classes/File.php
Possible hack for tags from private dents in public profile or wrong scope (both...
[quix0rs-gnu-social.git] / classes / File.php
index aee16e132d80549966ab453e79de494181c75731..1fcc83dd8845f22943d406627ddda6d4be7d01fb 100644 (file)
@@ -382,30 +382,35 @@ class File extends Managed_DataObject
      *
      * @return File_thumbnail
      */
-    public function getThumbnail($width=null, $height=null, $crop=false)
+    public function getThumbnail($width=null, $height=null, $crop=false, $force_still=true)
     {
-        if (intval($this->width) < 1 || intval($this->height) < 1) {
-            // Old files may have 0 until migrated with scripts/upgrade.php
-            // For any legitimately unrepresentable ones, we could generate our
-            // own image (like a square with MIME type in text)
-            throw new UnsupportedMediaException('No image geometry available.');
+        // Get some more information about this file through our ImageFile class
+        $image = ImageFile::fromFileObject($this);
+        if ($image->animated && !common_config('thumbnail', 'animated')) {
+            // null  means "always use file as thumbnail"
+            // false means you get choice between frozen frame or original when calling getThumbnail
+            if (is_null(common_config('thumbnail', 'animated')) || !$force_still) {
+                throw new UseFileAsThumbnailException($this->id);
+            }
         }
 
-        if ($width === null) {
+        if ($width === null || $width < 1) {
             $width = common_config('thumbnail', 'width');
             $height = common_config('thumbnail', 'height');
             $crop = common_config('thumbnail', 'crop');
         }
 
-        if ($height === null) {
+        if ($height === null || $height < 1) {
             $height = $width;
             $crop = true;
         }
 
+        // Debug log (convert crop to int to have TRUE being displayed as 1 and FALSE as 0)
+        common_debug('[' . __METHOD__ . ':' . __LINE__ . ']: width=' . $width . ',height=' . $height . ',crop=' . intval($crop));
+
         // Get proper aspect ratio width and height before lookup
         // We have to do it through an ImageFile object because of orientation etc.
         // Only other solution would've been to rotate + rewrite uploaded files.
-        $image = ImageFile::fromFileObject($this);
         list($width, $height, $x, $y, $w, $h) =
                                 $image->scaleToFit($width, $height, $crop);
 
@@ -418,7 +423,7 @@ class File extends Managed_DataObject
         }
 
         // throws exception on failure to generate thumbnail
-        $outname = "thumb-{$width}x{$height}-" . $this->filename;
+        $outname = "thumb-{$width}x{$height}-" . $image->filename;
         $outpath = self::path($outname);
 
         // The boundary box for our resizing
@@ -429,8 +434,8 @@ class File extends Managed_DataObject
         // Doublecheck that parameters are sane and integers.
         if ($box['width'] < 1 || $box['width'] > common_config('thumbnail', 'maxsize')
                 || $box['height'] < 1 || $box['height'] > common_config('thumbnail', 'maxsize')
-                || $box['w'] < 1 || $box['x'] >= $this->width
-                || $box['h'] < 1 || $box['y'] >= $this->height) {
+                || $box['w'] < 1 || $box['x'] >= $image->width
+                || $box['h'] < 1 || $box['y'] >= $image->height) {
             // Fail on bad width parameter. If this occurs, it's due to algorithm in ImageFile->scaleToFit
             common_debug("Boundary box parameters for resize of {$this->filepath} : ".var_export($box,true));
             throw new ServerException('Bad thumbnail size parameters. maxsize=' .
@@ -448,11 +453,12 @@ class File extends Managed_DataObject
             );
         }
 
+        common_debug(sprintf('Generating a thumbnail of File id==%u of size %ux%u', $this->id, $width, $height));
         // Perform resize and store into file
         $image->resizeTo($outpath, $box);
 
         // Avoid deleting the original
-        if ($image->getPath() != $this->getPath()) {
+        if ($image->getPath() != self::path($image->filename)) {
             $image->unlink();
         }
         return File_thumbnail::saveThumbnail($this->id,