@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.

Support imagemagick on new image transform pathway

Summary: Ref T7707. For animated GIFs, use imagemagick if it is available.

Test Plan: Generated small versions of a bunch of different GIFs.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T7707

Differential Revision: https://secure.phabricator.com/D12813

+47 -1
+47 -1
src/applications/files/transform/PhabricatorFileImageTransform.php
··· 42 42 $off_x = ($dst_w - $cpy_w) / 2; 43 43 $off_y = ($dst_h - $cpy_h) / 2; 44 44 45 - // TODO: Support imagemagick for animated GIFs. 45 + if ($this->shouldUseImagemagick()) { 46 + $argv = array(); 47 + $argv[] = '-coalesce'; 48 + $argv[] = '-shave'; 49 + $argv[] = $src_x.'x'.$src_y; 50 + $argv[] = '-resize'; 51 + $argv[] = $dst_w.'x'.$dst_h.'>'; 52 + $argv[] = '-bordercolor'; 53 + $argv[] = 'rgba(255, 255, 255, 0)'; 54 + $argv[] = '-border'; 55 + $argv[] = $off_x.'x'.$off_y; 56 + return $this->applyImagemagick($argv); 57 + } 46 58 47 59 $src = $this->getImage(); 48 60 $dst = $this->newEmptyImage($dst_w, $dst_h); ··· 68 80 $data = PhabricatorImageTransformer::saveImageDataInAnyFormat( 69 81 $dst, 70 82 $this->file->getMimeType()); 83 + 84 + return $this->newFileFromData($data); 85 + } 86 + 87 + protected function applyImagemagick(array $argv) { 88 + $tmp = new TempFile(); 89 + Filesystem::writeFile($tmp, $this->getData()); 90 + 91 + $out = new TempFile(); 92 + 93 + $future = new ExecFuture('convert %s %Ls %s', $tmp, $argv, $out); 94 + // Don't spend more than 10 seconds resizing; just fail if it takes longer 95 + // than that. 96 + $future->setTimeout(10)->resolvex(); 97 + 98 + $data = Filesystem::readFile($out); 71 99 72 100 return $this->newFileFromData($data); 73 101 } ··· 297 325 298 326 $this->image = $image; 299 327 return $this->image; 328 + } 329 + 330 + private function shouldUseImagemagick() { 331 + if (!PhabricatorEnv::getEnvConfig('files.enable-imagemagick')) { 332 + return false; 333 + } 334 + 335 + if ($this->file->getMimeType() != 'image/gif') { 336 + return false; 337 + } 338 + 339 + // Don't try to preserve the animation in huge GIFs. 340 + list($x, $y) = $this->getImageDimensions(); 341 + if (($x * $y) > (512 * 512)) { 342 + return false; 343 + } 344 + 345 + return true; 300 346 } 301 347 302 348 }