mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-23 05:50:55 +01:00
improve image hinting for 220 preview
Summary: break out the calculation of dimensions as a static method and use it Test Plan: made a conpherence with many images and noted i auto-scrolled to the bottom correctly Reviewers: chad, epriestley Reviewed By: epriestley CC: aran, Korvin Maniphest Tasks: T2399 Differential Revision: https://secure.phabricator.com/D4733
This commit is contained in:
parent
9e7ac9a47e
commit
3ee9921f2d
2 changed files with 30 additions and 5 deletions
|
@ -116,7 +116,7 @@ final class PhabricatorImageTransformer {
|
||||||
return $dst;
|
return $dst;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function generatePreview(PhabricatorFile $file, $size) {
|
public static function getPreviewDimensions(PhabricatorFile $file, $size) {
|
||||||
$data = $file->loadFileData();
|
$data = $file->loadFileData();
|
||||||
$src = imagecreatefromstring($data);
|
$src = imagecreatefromstring($data);
|
||||||
|
|
||||||
|
@ -128,13 +128,35 @@ final class PhabricatorImageTransformer {
|
||||||
$dx = max($size / 4, $scale * $x);
|
$dx = max($size / 4, $scale * $x);
|
||||||
$dy = max($size / 4, $scale * $y);
|
$dy = max($size / 4, $scale * $y);
|
||||||
|
|
||||||
|
$sdx = $scale * $x;
|
||||||
|
$sdy = $scale * $y;
|
||||||
|
|
||||||
|
return array(
|
||||||
|
'x' => $x,
|
||||||
|
'y' => $y,
|
||||||
|
'dx' => $dx,
|
||||||
|
'dy' => $dy,
|
||||||
|
'sdx' => $sdx,
|
||||||
|
'sdy' => $sdy
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function generatePreview(PhabricatorFile $file, $size) {
|
||||||
|
$data = $file->loadFileData();
|
||||||
|
$src = imagecreatefromstring($data);
|
||||||
|
|
||||||
|
$dimensions = self::getPreviewDimensions($file, $size);
|
||||||
|
$x = $dimensions['x'];
|
||||||
|
$y = $dimensions['y'];
|
||||||
|
$dx = $dimensions['dx'];
|
||||||
|
$dy = $dimensions['dy'];
|
||||||
|
$sdx = $dimensions['sdx'];
|
||||||
|
$sdy = $dimensions['sdy'];
|
||||||
|
|
||||||
$dst = imagecreatetruecolor($dx, $dy);
|
$dst = imagecreatetruecolor($dx, $dy);
|
||||||
imagesavealpha($dst, true);
|
imagesavealpha($dst, true);
|
||||||
imagefill($dst, 0, 0, imagecolorallocatealpha($dst, 255, 255, 255, 127));
|
imagefill($dst, 0, 0, imagecolorallocatealpha($dst, 255, 255, 255, 127));
|
||||||
|
|
||||||
$sdx = $scale * $x;
|
|
||||||
$sdy = $scale * $y;
|
|
||||||
|
|
||||||
imagecopyresampled(
|
imagecopyresampled(
|
||||||
$dst,
|
$dst,
|
||||||
$src,
|
$src,
|
||||||
|
|
|
@ -68,7 +68,10 @@ final class PhabricatorRemarkupRuleEmbedFile
|
||||||
case 'thumb':
|
case 'thumb':
|
||||||
default:
|
default:
|
||||||
$attrs['src'] = $file->getPreview220URI();
|
$attrs['src'] = $file->getPreview220URI();
|
||||||
$attrs['width'] = '220';
|
$dimensions =
|
||||||
|
PhabricatorImageTransformer::getPreviewDimensions($file, 220);
|
||||||
|
$attrs['width'] = $dimensions['sdx'];
|
||||||
|
$attrs['height'] = $dimensions['sdy'];
|
||||||
$options['image_class'] = 'phabricator-remarkup-embed-image';
|
$options['image_class'] = 'phabricator-remarkup-embed-image';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue