Skip to content

Commit c146c94

Browse files
author
epriestley
committed
Fix meme generation for palette PNGs
Summary: Fixes T4125. Indexed / palette PNGs may fail to allocate a proper black for drawing an image border. Test Plan: {F83066} Reviewers: btrahan, asukhachev Reviewed By: asukhachev CC: aran Maniphest Tasks: T4125 Differential Revision: https://secure.phabricator.com/D7604
1 parent 476b27d commit c146c94

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/applications/files/PhabricatorImageTransformer.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,15 @@ private function applyMemeTo(
294294
$lower_text,
295295
$mime_type) {
296296
$img = imagecreatefromstring($data);
297+
298+
// Some PNGs have color palettes, and allocating the dark border color
299+
// fails and gives us whatever's first in the color table. Copy the image
300+
// to a fresh truecolor canvas before working with it.
301+
302+
$truecolor = imagecreatetruecolor(imagesx($img), imagesy($img));
303+
imagecopy($truecolor, $img, 0, 0, 0, 0, imagesx($img), imagesy($img));
304+
$img = $truecolor;
305+
297306
$phabricator_root = dirname(phutil_get_library_root('phabricator'));
298307
$font_root = $phabricator_root.'/resources/font/';
299308
$font_path = $font_root.'tuffy.ttf';

0 commit comments

Comments
 (0)