Page MenuHomePhabricator

D12814.diff
No OneTemporary

D12814.diff

diff --git a/src/applications/files/PhabricatorImageTransformer.php b/src/applications/files/PhabricatorImageTransformer.php
--- a/src/applications/files/PhabricatorImageTransformer.php
+++ b/src/applications/files/PhabricatorImageTransformer.php
@@ -51,20 +51,6 @@
));
}
- public function executePreviewTransform(
- PhabricatorFile $file,
- $size) {
-
- $image = $this->generatePreview($file, $size);
-
- return PhabricatorFile::newFromFileData(
- $image,
- array(
- 'name' => 'preview-'.$file->getName(),
- 'canCDN' => true,
- ));
- }
-
public function executeConpherenceTransform(
PhabricatorFile $file,
$top,
@@ -188,37 +174,6 @@
}
- public static function getPreviewDimensions(PhabricatorFile $file, $size) {
- $metadata = $file->getMetadata();
- $x = idx($metadata, PhabricatorFile::METADATA_IMAGE_WIDTH);
- $y = idx($metadata, PhabricatorFile::METADATA_IMAGE_HEIGHT);
-
- if (!$x || !$y) {
- $data = $file->loadFileData();
- $src = imagecreatefromstring($data);
-
- $x = imagesx($src);
- $y = imagesy($src);
- }
-
- $scale = min($size / $x, $size / $y, 1);
-
- $dx = max($size / 4, $scale * $x);
- $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,
- );
- }
-
public static function getScaleForCrop(
PhabricatorFile $file,
$des_width,
@@ -241,31 +196,6 @@
return $scale;
}
- 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 = $this->getBlankDestinationFile($dx, $dy);
-
- imagecopyresampled(
- $dst,
- $src,
- ($dx - $sdx) / 2, ($dy - $sdy) / 2,
- 0, 0,
- $sdx, $sdy,
- $x, $y);
-
- return self::saveImageDataInAnyFormat($dst, $file->getMimeType());
- }
-
private function applyMemeToFile(
PhabricatorFile $file,
$upper_text,
diff --git a/src/applications/files/controller/PhabricatorFileTransformController.php b/src/applications/files/controller/PhabricatorFileTransformController.php
--- a/src/applications/files/controller/PhabricatorFileTransformController.php
+++ b/src/applications/files/controller/PhabricatorFileTransformController.php
@@ -85,12 +85,6 @@
case 'thumb-280x210':
$xformed_file = $this->executeThumbTransform($file, 280, 210);
break;
- case 'preview-100':
- $xformed_file = $this->executePreviewTransform($file, 100);
- break;
- case 'preview-220':
- $xformed_file = $this->executePreviewTransform($file, 220);
- break;
default:
return new Aphront400Response();
}
@@ -132,9 +126,6 @@
case 'thumb-280x210':
$suffix = '280x210';
break;
- case 'preview-100':
- $suffix = '.p100';
- break;
default:
throw new Exception('Unsupported transformation type!');
}
@@ -163,11 +154,6 @@
return $file->getRedirectResponse();
}
- private function executePreviewTransform(PhabricatorFile $file, $size) {
- $xformer = new PhabricatorImageTransformer();
- return $xformer->executePreviewTransform($file, $size);
- }
-
private function executeThumbTransform(PhabricatorFile $file, $x, $y) {
$xformer = new PhabricatorImageTransformer();
return $xformer->executeThumbTransform($file, $x, $y);
diff --git a/src/applications/files/markup/PhabricatorEmbedFileRemarkupRule.php b/src/applications/files/markup/PhabricatorEmbedFileRemarkupRule.php
--- a/src/applications/files/markup/PhabricatorEmbedFileRemarkupRule.php
+++ b/src/applications/files/markup/PhabricatorEmbedFileRemarkupRule.php
@@ -107,11 +107,17 @@
break;
case 'thumb':
default:
- $attrs['src'] = $file->getPreview220URI();
- $dimensions =
- PhabricatorImageTransformer::getPreviewDimensions($file, 220);
- $attrs['width'] = $dimensions['dx'];
- $attrs['height'] = $dimensions['dy'];
+ $preview_key = PhabricatorFileThumbnailTransform::TRANSFORM_PREVIEW;
+ $xform = PhabricatorFileTransform::getTransformByKey($preview_key);
+ $attrs['src'] = $file->getURIForTransform($xform);
+
+ $dimensions = $xform->getTransformedDimensions($file);
+ if ($dimensions) {
+ list($x, $y) = $dimensions;
+ $attrs['width'] = $x;
+ $attrs['height'] = $y;
+ }
+
$image_class = 'phabricator-remarkup-embed-image';
break;
}
diff --git a/src/applications/files/storage/PhabricatorFile.php b/src/applications/files/storage/PhabricatorFile.php
--- a/src/applications/files/storage/PhabricatorFile.php
+++ b/src/applications/files/storage/PhabricatorFile.php
@@ -788,14 +788,6 @@
return $this->getTransformedURI('thumb-profile');
}
- public function getPreview100URI() {
- return $this->getTransformedURI('preview-100');
- }
-
- public function getPreview220URI() {
- return $this->getTransformedURI('preview-220');
- }
-
public function getThumb280x210URI() {
return $this->getTransformedURI('thumb-280x210');
}
diff --git a/src/applications/files/transform/PhabricatorFileImageTransform.php b/src/applications/files/transform/PhabricatorFileImageTransform.php
--- a/src/applications/files/transform/PhabricatorFileImageTransform.php
+++ b/src/applications/files/transform/PhabricatorFileImageTransform.php
@@ -8,6 +8,16 @@
private $imageX;
private $imageY;
+ /**
+ * Get an estimate of the transformed dimensions of a file.
+ *
+ * @param PhabricatorFile File to transform.
+ * @return list<int, int>|null Width and height, if available.
+ */
+ public function getTransformedDimensions(PhabricatorFile $file) {
+ return null;
+ }
+
public function canApplyTransform(PhabricatorFile $file) {
if (!$file->isViewableImage()) {
return false;
diff --git a/src/applications/files/transform/PhabricatorFileThumbnailTransform.php b/src/applications/files/transform/PhabricatorFileThumbnailTransform.php
--- a/src/applications/files/transform/PhabricatorFileThumbnailTransform.php
+++ b/src/applications/files/transform/PhabricatorFileThumbnailTransform.php
@@ -65,6 +65,59 @@
$dst_x = $this->dstX;
$dst_y = $this->dstY;
+ $dimensions = $this->computeDimensions(
+ $src_x,
+ $src_y,
+ $dst_x,
+ $dst_y);
+
+ $copy_x = $dimensions['copy_x'];
+ $copy_y = $dimensions['copy_y'];
+ $use_x = $dimensions['use_x'];
+ $use_y = $dimensions['use_y'];
+ $dst_x = $dimensions['dst_x'];
+ $dst_y = $dimensions['dst_y'];
+
+ return $this->applyCropAndScale(
+ $dst_x,
+ $dst_y,
+ ($src_x - $copy_x) / 2,
+ ($src_y - $copy_y) / 2,
+ $copy_x,
+ $copy_y,
+ $use_x,
+ $use_y);
+ }
+
+
+ public function getTransformedDimensions(PhabricatorFile $file) {
+ $dst_x = $this->dstX;
+ $dst_y = $this->dstY;
+
+ // If this is transform has fixed dimensions, we can trivially predict
+ // the dimensions of the transformed file.
+ if ($dst_y !== null) {
+ return array($dst_x, $dst_y);
+ }
+
+ $src_x = $file->getImageWidth();
+ $src_y = $file->getImageHeight();
+
+ if (!$src_x || !$src_y) {
+ return null;
+ }
+
+ $dimensions = $this->computeDimensions(
+ $src_x,
+ $src_y,
+ $dst_x,
+ $dst_y);
+
+ return array($dimensions['dst_x'], $dimensions['dst_y']);
+ }
+
+
+ private function computeDimensions($src_x, $src_y, $dst_x, $dst_y) {
if ($dst_y === null) {
// If we only have one dimension, it represents a maximum dimension.
// The other dimension of the transform is scaled appropriately, except
@@ -115,17 +168,17 @@
$use_y = $dst_y;
}
- return $this->applyCropAndScale(
- $dst_x,
- $dst_y,
- ($src_x - $copy_x) / 2,
- ($src_y - $copy_y) / 2,
- $copy_x,
- $copy_y,
- $use_x,
- $use_y);
+ return array(
+ 'copy_x' => $copy_x,
+ 'copy_y' => $copy_y,
+ 'use_x' => $use_x,
+ 'use_y' => $use_y,
+ 'dst_x' => $dst_x,
+ 'dst_y' => $dst_y,
+ );
}
+
public function getDefaultTransform(PhabricatorFile $file) {
$x = (int)$this->dstX;
$y = (int)$this->dstY;
diff --git a/src/applications/files/transform/PhabricatorFileTransform.php b/src/applications/files/transform/PhabricatorFileTransform.php
--- a/src/applications/files/transform/PhabricatorFileTransform.php
+++ b/src/applications/files/transform/PhabricatorFileTransform.php
@@ -45,4 +45,18 @@
return $map;
}
+ public static function getTransformByKey($key) {
+ $all = self::getAllTransforms();
+
+ $xform = idx($all, $key);
+ if (!$xform) {
+ throw new Exception(
+ pht(
+ 'No file transform with key "%s" exists.',
+ $key));
+ }
+
+ return $xform;
+ }
+
}
diff --git a/src/applications/pholio/view/PholioMockThumbGridView.php b/src/applications/pholio/view/PholioMockThumbGridView.php
--- a/src/applications/pholio/view/PholioMockThumbGridView.php
+++ b/src/applications/pholio/view/PholioMockThumbGridView.php
@@ -114,28 +114,34 @@
private function renderThumbnail(PholioImage $image) {
$thumbfile = $image->getFile();
+ $preview_key = PhabricatorFileThumbnailTransform::TRANSFORM_THUMBGRID;
+ $xform = PhabricatorFileTransform::getTransformByKey($preview_key);
+
+ $attributes = array(
+ 'class' => 'pholio-mock-thumb-grid-image',
+ 'src' => $thumbfile->getURIForTransform($xform),
+ );
+
if ($image->getFile()->isViewableImage()) {
- $dimensions = PhabricatorImageTransformer::getPreviewDimensions(
- $thumbfile,
- 100);
+ $dimensions = $xform->getTransformedDimensions($thumbfile);
+ if ($dimensions) {
+ list($x, $y) = $dimensions;
+ $attributes += array(
+ 'width' => $x,
+ 'height' => $y,
+ 'style' => 'top: '.floor((100 - $y) / 2).'px',
+ );
+ }
} else {
// If this is a PDF or a text file or something, we'll end up using a
// generic thumbnail which is always sized correctly.
- $dimensions = array(
- 'sdx' => 100,
- 'sdy' => 100,
+ $attributes += array(
+ 'width' => 100,
+ 'height' => 100,
);
}
- $tag = phutil_tag(
- 'img',
- array(
- 'width' => $dimensions['sdx'],
- 'height' => $dimensions['sdy'],
- 'src' => $thumbfile->getPreview100URI(),
- 'class' => 'pholio-mock-thumb-grid-image',
- 'style' => 'top: '.floor((100 - $dimensions['sdy'] ) / 2).'px',
- ));
+ $tag = phutil_tag('img', $attributes);
$classes = array('pholio-mock-thumb-grid-item');
if ($image->getIsObsolete()) {
diff --git a/webroot/rsrc/image/icon/fatcow/thumbnails/default.p100.png b/webroot/rsrc/image/icon/fatcow/thumbnails/default.p100.png
deleted file mode 100644
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000
GIT binary patch
literal 0
Hc$@<O00001
literal 0
Hc$@<O00001
diff --git a/webroot/rsrc/image/icon/fatcow/thumbnails/image.p100.png b/webroot/rsrc/image/icon/fatcow/thumbnails/image.p100.png
deleted file mode 100644
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000
GIT binary patch
literal 0
Hc$@<O00001
literal 0
Hc$@<O00001
diff --git a/webroot/rsrc/image/icon/fatcow/thumbnails/pdf.p100.png b/webroot/rsrc/image/icon/fatcow/thumbnails/pdf.p100.png
deleted file mode 100644
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000
GIT binary patch
literal 0
Hc$@<O00001
literal 0
Hc$@<O00001
diff --git a/webroot/rsrc/image/icon/fatcow/thumbnails/zip.p100.png b/webroot/rsrc/image/icon/fatcow/thumbnails/zip.p100.png
deleted file mode 100644
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000
GIT binary patch
literal 0
Hc$@<O00001
literal 0
Hc$@<O00001

File Metadata

Mime Type
text/plain
Expires
Fri, Dec 27, 6:43 AM (10 h, 46 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6931240
Default Alt Text
D12814.diff (12 KB)

Event Timeline