mirror of
https://we.phorge.it/source/phorge.git
synced 2025-03-12 12:24:50 +01:00
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
This commit is contained in:
parent
aaff2415f9
commit
6facee6140
3 changed files with 33 additions and 7 deletions
|
@ -334,7 +334,8 @@ abstract class PhabricatorFileImageTransform extends PhabricatorFileTransform {
|
||||||
'Unable to determine image width and height with getimagesize().'));
|
'Unable to determine image width and height with getimagesize().'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$max_pixels = (4096 * 4096);
|
$max_pixels_array = $this->getMaxTransformDimensions();
|
||||||
|
$max_pixels = ($max_pixels_array[0] * $max_pixels_array[1]);
|
||||||
$img_pixels = ($width * $height);
|
$img_pixels = ($width * $height);
|
||||||
|
|
||||||
if ($img_pixels > $max_pixels) {
|
if ($img_pixels > $max_pixels) {
|
||||||
|
@ -365,6 +366,15 @@ abstract class PhabricatorFileImageTransform extends PhabricatorFileTransform {
|
||||||
return $this->image;
|
return $this->image;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get maximum supported image dimensions in pixels for transforming
|
||||||
|
*
|
||||||
|
* @return array<int> Maximum width and height
|
||||||
|
*/
|
||||||
|
public function getMaxTransformDimensions() {
|
||||||
|
return array(4096, 4096);
|
||||||
|
}
|
||||||
|
|
||||||
private function shouldUseImagemagick() {
|
private function shouldUseImagemagick() {
|
||||||
if (!PhabricatorEnv::getEnvConfig('files.enable-imagemagick')) {
|
if (!PhabricatorEnv::getEnvConfig('files.enable-imagemagick')) {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -36,6 +36,15 @@ final class PhabricatorPeopleProfilePictureController
|
||||||
$e_file = true;
|
$e_file = true;
|
||||||
$errors = array();
|
$errors = array();
|
||||||
|
|
||||||
|
// Get the image file transform.
|
||||||
|
$xform = PhabricatorFileTransform::getTransformByKey(
|
||||||
|
PhabricatorFileThumbnailTransform::TRANSFORM_PROFILE);
|
||||||
|
|
||||||
|
// Have an hard-limit to save our resources.
|
||||||
|
$max_image_dimensions = $xform->getMaxTransformDimensions();
|
||||||
|
$max_image_dimensions_message = pht('Maximum image dimensions: %s pixels.',
|
||||||
|
implode(mb_chr(215), $max_image_dimensions));
|
||||||
|
|
||||||
if ($request->isFormPost()) {
|
if ($request->isFormPost()) {
|
||||||
$phid = $request->getStr('phid');
|
$phid = $request->getStr('phid');
|
||||||
$is_default = false;
|
$is_default = false;
|
||||||
|
@ -67,8 +76,6 @@ final class PhabricatorPeopleProfilePictureController
|
||||||
$e_file = pht('Not Supported');
|
$e_file = pht('Not Supported');
|
||||||
$errors[] = $supported_formats_message;
|
$errors[] = $supported_formats_message;
|
||||||
} else {
|
} else {
|
||||||
$xform = PhabricatorFileTransform::getTransformByKey(
|
|
||||||
PhabricatorFileThumbnailTransform::TRANSFORM_PROFILE);
|
|
||||||
$xformed = $xform->executeTransform($file);
|
$xformed = $xform->executeTransform($file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -254,7 +261,8 @@ final class PhabricatorPeopleProfilePictureController
|
||||||
->setName('picture')
|
->setName('picture')
|
||||||
->setLabel(pht('Upload Picture'))
|
->setLabel(pht('Upload Picture'))
|
||||||
->setError($e_file)
|
->setError($e_file)
|
||||||
->setCaption($supported_formats_message))
|
->setCaption($supported_formats_message.' '.
|
||||||
|
$max_image_dimensions_message))
|
||||||
->appendChild(
|
->appendChild(
|
||||||
id(new AphrontFormSubmitControl())
|
id(new AphrontFormSubmitControl())
|
||||||
->addCancelButton($done_uri)
|
->addCancelButton($done_uri)
|
||||||
|
|
|
@ -35,6 +35,15 @@ final class PhabricatorProjectEditPictureController
|
||||||
$e_file = true;
|
$e_file = true;
|
||||||
$errors = array();
|
$errors = array();
|
||||||
|
|
||||||
|
// Get the image file transform.
|
||||||
|
$xform = PhabricatorFileTransform::getTransformByKey(
|
||||||
|
PhabricatorFileThumbnailTransform::TRANSFORM_PROFILE);
|
||||||
|
|
||||||
|
// Have an hard-limit to save our resources.
|
||||||
|
$max_image_dimensions = $xform->getMaxTransformDimensions();
|
||||||
|
$max_image_dimensions_message = pht('Maximum image dimensions: %s pixels.',
|
||||||
|
implode(mb_chr(215), $max_image_dimensions));
|
||||||
|
|
||||||
if ($request->isFormPost()) {
|
if ($request->isFormPost()) {
|
||||||
$phid = $request->getStr('phid');
|
$phid = $request->getStr('phid');
|
||||||
$is_default = false;
|
$is_default = false;
|
||||||
|
@ -66,8 +75,6 @@ final class PhabricatorProjectEditPictureController
|
||||||
$e_file = pht('Not Supported');
|
$e_file = pht('Not Supported');
|
||||||
$errors[] = $supported_formats_message;
|
$errors[] = $supported_formats_message;
|
||||||
} else {
|
} else {
|
||||||
$xform = PhabricatorFileTransform::getTransformByKey(
|
|
||||||
PhabricatorFileThumbnailTransform::TRANSFORM_PROFILE);
|
|
||||||
$xformed = $xform->executeTransform($file);
|
$xformed = $xform->executeTransform($file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -261,7 +268,8 @@ final class PhabricatorProjectEditPictureController
|
||||||
->setName('picture')
|
->setName('picture')
|
||||||
->setLabel(pht('Upload Picture'))
|
->setLabel(pht('Upload Picture'))
|
||||||
->setError($e_file)
|
->setError($e_file)
|
||||||
->setCaption($supported_formats_message))
|
->setCaption($supported_formats_message.' '.
|
||||||
|
$max_image_dimensions_message))
|
||||||
->appendChild(
|
->appendChild(
|
||||||
id(new AphrontFormSubmitControl())
|
id(new AphrontFormSubmitControl())
|
||||||
->addCancelButton($manage_uri)
|
->addCancelButton($manage_uri)
|
||||||
|
|
Loading…
Add table
Reference in a new issue