@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Communicate max dimensions of profile images before upload

Summary:
Trying to set a large image as a project profile image, Phorge displays the "it is a mystery" placeholder image without errors or explanation.
Thus communicate the maximum file dimensions for transforming thumbnails, like Phorge already does for supported file format types.

Closes T15984

Test Plan:
* Go to http://phorge.localhost/project/picture/1/ and http://phorge.localhost/people/picture/1/ and set an image with 4096×4096px and an image with 4097×4097px and observe resulting image.
* Apply this patch, then go to http://phorge.localhost/project/picture/1/ and http://phorge.localhost/people/picture/1/ and see the additional "Maximum image dimensions: 4096×4096 pixels." in the "Upload New Picture" section, set an image with 4096×4096px and an image with 4097×4097px.
* Also test on http://phorge.localhost/phame/post/header/1/ and http://phorge.localhost/phame/blog/header/1/ but realize that these codepaths do not transform larger images, thus no problem. I remain clueless how to trigger PhameBlogProfilePictureController, DiffusionRepositoryProfilePictureController with similar code.

Reviewers: O1 Blessed Committers, valerio.bozzolan

Reviewed By: O1 Blessed Committers, valerio.bozzolan

Subscribers: avivey, tobiaswiese, valerio.bozzolan, Matthew, Cigaryno

Maniphest Tasks: T15984

Differential Revision: https://we.phorge.it/D25862

+33 -7
+11 -1
src/applications/files/transform/PhabricatorFileImageTransform.php
··· 334 334 'Unable to determine image width and height with getimagesize().')); 335 335 } 336 336 337 - $max_pixels = (4096 * 4096); 337 + $max_pixels_array = $this->getMaxTransformDimensions(); 338 + $max_pixels = ($max_pixels_array[0] * $max_pixels_array[1]); 338 339 $img_pixels = ($width * $height); 339 340 340 341 if ($img_pixels > $max_pixels) { ··· 363 364 364 365 $this->image = $image; 365 366 return $this->image; 367 + } 368 + 369 + /** 370 + * Get maximum supported image dimensions in pixels for transforming 371 + * 372 + * @return array<int> Maximum width and height 373 + */ 374 + public function getMaxTransformDimensions() { 375 + return array(4096, 4096); 366 376 } 367 377 368 378 private function shouldUseImagemagick() {
+11 -3
src/applications/people/controller/PhabricatorPeopleProfilePictureController.php
··· 36 36 $e_file = true; 37 37 $errors = array(); 38 38 39 + // Get the image file transform. 40 + $xform = PhabricatorFileTransform::getTransformByKey( 41 + PhabricatorFileThumbnailTransform::TRANSFORM_PROFILE); 42 + 43 + // Have an hard-limit to save our resources. 44 + $max_image_dimensions = $xform->getMaxTransformDimensions(); 45 + $max_image_dimensions_message = pht('Maximum image dimensions: %s pixels.', 46 + implode(mb_chr(215), $max_image_dimensions)); 47 + 39 48 if ($request->isFormPost()) { 40 49 $phid = $request->getStr('phid'); 41 50 $is_default = false; ··· 67 76 $e_file = pht('Not Supported'); 68 77 $errors[] = $supported_formats_message; 69 78 } else { 70 - $xform = PhabricatorFileTransform::getTransformByKey( 71 - PhabricatorFileThumbnailTransform::TRANSFORM_PROFILE); 72 79 $xformed = $xform->executeTransform($file); 73 80 } 74 81 } ··· 254 261 ->setName('picture') 255 262 ->setLabel(pht('Upload Picture')) 256 263 ->setError($e_file) 257 - ->setCaption($supported_formats_message)) 264 + ->setCaption($supported_formats_message.' '. 265 + $max_image_dimensions_message)) 258 266 ->appendChild( 259 267 id(new AphrontFormSubmitControl()) 260 268 ->addCancelButton($done_uri)
+11 -3
src/applications/project/controller/PhabricatorProjectEditPictureController.php
··· 35 35 $e_file = true; 36 36 $errors = array(); 37 37 38 + // Get the image file transform. 39 + $xform = PhabricatorFileTransform::getTransformByKey( 40 + PhabricatorFileThumbnailTransform::TRANSFORM_PROFILE); 41 + 42 + // Have an hard-limit to save our resources. 43 + $max_image_dimensions = $xform->getMaxTransformDimensions(); 44 + $max_image_dimensions_message = pht('Maximum image dimensions: %s pixels.', 45 + implode(mb_chr(215), $max_image_dimensions)); 46 + 38 47 if ($request->isFormPost()) { 39 48 $phid = $request->getStr('phid'); 40 49 $is_default = false; ··· 66 75 $e_file = pht('Not Supported'); 67 76 $errors[] = $supported_formats_message; 68 77 } else { 69 - $xform = PhabricatorFileTransform::getTransformByKey( 70 - PhabricatorFileThumbnailTransform::TRANSFORM_PROFILE); 71 78 $xformed = $xform->executeTransform($file); 72 79 } 73 80 } ··· 261 268 ->setName('picture') 262 269 ->setLabel(pht('Upload Picture')) 263 270 ->setError($e_file) 264 - ->setCaption($supported_formats_message)) 271 + ->setCaption($supported_formats_message.' '. 272 + $max_image_dimensions_message)) 265 273 ->appendChild( 266 274 id(new AphrontFormSubmitControl()) 267 275 ->addCancelButton($manage_uri)