@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

Avoid exception setting project profile image when GD not installed

Summary:
When trying to set a custom project profile image while the PHP GD extension is not installed, use the same logic which already exists in `PhabricatorFilesComposeAvatarBuiltinFile.php` to set the default project image. This stills display an unhelpful error message `This server only supports these image formats: .` but avoids an exception trying to call GD's `imagecreatefromstring()`.

```
EXCEPTION: (Error) Call to undefined function imagecreatefromstring() at [<phorge>/src/applications/files/builtin/PhabricatorFilesComposeIconBuiltinFile.php:131]
```

Closes T15326

Test Plan:
1. Remove the php-gd (and potentially gd) packages on your system; restart httpd
2. Go to http://phorge.localhost/project/manage/1/
3. Select `Edit Picture` in the sidebar on the right to go to the `Edit Project Picture` at http://phorge.localhost/project/picture/1/
4. Set a custom icon and color and click the `Save Image` button
5. Get `This server only supports these image formats: .` but no exception anymore

Reviewers: O1 Blessed Committers, avivey, valerio.bozzolan

Reviewed By: O1 Blessed Committers, avivey, valerio.bozzolan

Subscribers: avivey, tobiaswiese, valerio.bozzolan, Matthew, Cigaryno

Maniphest Tasks: T15326

Differential Revision: https://we.phorge.it/D25515

+8
+8
src/applications/files/builtin/PhabricatorFilesComposeIconBuiltinFile.php
··· 98 98 } 99 99 100 100 private function composeImage($color, $icon) { 101 + // If we don't have the GD extension installed, just return a static 102 + // default project image rather than trying to compose one. 103 + if (!function_exists('imagecreatefromstring')) { 104 + $root = dirname(phutil_get_library_root('phabricator')); 105 + $default_path = $root.'/resources/builtin/profile.png'; 106 + return Filesystem::readFile($default_path); 107 + } 108 + 101 109 $color_map = self::getAllColors(); 102 110 $color = idx($color_map, $color); 103 111 if (!$color) {