From c206b066df386fd6724df1e6eb1500ad46f0e535 Mon Sep 17 00:00:00 2001 From: epriestley Date: Tue, 6 Nov 2018 09:07:30 -0800 Subject: [PATCH] When `{meme ...}` embed has no text, just use the raw file data unmodified Summary: Ref T13216. See PHI948. When you use the remarkup hint button to embed a meme with no text, you get `{meme src=X}`. If the source is a GIF, we currently split the source apart into frame-by-frame images, process them, and stitch them back together. The end result is the same image we started with, but this process can be slow/expensive, and may timeout for sufficiently large GIFs. Instead: when there's no text, just return the original image data. Test Plan: - Used `{meme src=X}` with no text, got an image faster. - Used `{meme src=X, above=...}` to add text, got an attempt to add text (which didn't get very far locally since I don't have GD configured). Reviewers: amckinley Reviewed By: amckinley Maniphest Tasks: T13216 Differential Revision: https://secure.phabricator.com/D19777 --- src/applications/macro/engine/PhabricatorMemeEngine.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/applications/macro/engine/PhabricatorMemeEngine.php b/src/applications/macro/engine/PhabricatorMemeEngine.php index 3e87a304c9..7433a4e8bc 100644 --- a/src/applications/macro/engine/PhabricatorMemeEngine.php +++ b/src/applications/macro/engine/PhabricatorMemeEngine.php @@ -174,6 +174,15 @@ final class PhabricatorMemeEngine extends Phobject { private function newAssetData(PhabricatorFile $template) { $template_data = $template->loadFileData(); + // When we aren't adding text, just return the data unmodified. This saves + // us from doing expensive stitching when we aren't actually making any + // changes to the image. + $above_text = $this->getAboveText(); + $below_text = $this->getBelowText(); + if (!strlen(trim($above_text)) && !strlen(trim($below_text))) { + return $template_data; + } + $result = $this->newImagemagickAsset($template, $template_data); if ($result) { return $result;