From de9b00b8be934c8bdbfd1988ac90c15a50f09d83 Mon Sep 17 00:00:00 2001 From: epriestley Date: Tue, 16 Apr 2013 08:19:45 -0700 Subject: [PATCH] Add a basic random image generator Summary: Adds an abstract base class for random image generation. Implements a concrete subclass for generating Mondrian-like images. Test Plan: {F40759} {F40760} {F40761} {F40762} {F40763} Reviewers: DeedyDas, AnhNhan Reviewed By: AnhNhan CC: chad, aran Differential Revision: https://secure.phabricator.com/D5705 --- src/__phutil_library_map__.php | 3 + .../files/PhabricatorImageTransformer.php | 12 ++-- .../lipsum/image/PhabricatorLipsumArtist.php | 68 +++++++++++++++++++ .../image/PhabricatorLipsumMondrianArtist.php | 48 +++++++++++++ 4 files changed, 125 insertions(+), 6 deletions(-) create mode 100644 src/applications/lipsum/image/PhabricatorLipsumArtist.php create mode 100644 src/applications/lipsum/image/PhabricatorLipsumMondrianArtist.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 9095ebf08f..8d6e232caf 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -1037,8 +1037,10 @@ phutil_register_library_map(array( 'PhabricatorLDAPUnknownUserException' => 'applications/auth/ldap/PhabricatorLDAPUnknownUserException.php', 'PhabricatorLDAPUnlinkController' => 'applications/auth/controller/PhabricatorLDAPUnlinkController.php', 'PhabricatorLintEngine' => 'infrastructure/lint/PhabricatorLintEngine.php', + 'PhabricatorLipsumArtist' => 'applications/lipsum/image/PhabricatorLipsumArtist.php', 'PhabricatorLipsumGenerateWorkflow' => 'applications/lipsum/management/PhabricatorLipsumGenerateWorkflow.php', 'PhabricatorLipsumManagementWorkflow' => 'applications/lipsum/management/PhabricatorLipsumManagementWorkflow.php', + 'PhabricatorLipsumMondrianArtist' => 'applications/lipsum/image/PhabricatorLipsumMondrianArtist.php', 'PhabricatorLiskDAO' => 'infrastructure/storage/lisk/PhabricatorLiskDAO.php', 'PhabricatorLocalDiskFileStorageEngine' => 'applications/files/engine/PhabricatorLocalDiskFileStorageEngine.php', 'PhabricatorLocalTimeTestCase' => 'view/__tests__/PhabricatorLocalTimeTestCase.php', @@ -2739,6 +2741,7 @@ phutil_register_library_map(array( 'PhabricatorLintEngine' => 'PhutilLintEngine', 'PhabricatorLipsumGenerateWorkflow' => 'PhabricatorLipsumManagementWorkflow', 'PhabricatorLipsumManagementWorkflow' => 'PhutilArgumentWorkflow', + 'PhabricatorLipsumMondrianArtist' => 'PhabricatorLipsumArtist', 'PhabricatorLiskDAO' => 'LiskDAO', 'PhabricatorLocalDiskFileStorageEngine' => 'PhabricatorFileStorageEngine', 'PhabricatorLocalTimeTestCase' => 'PhabricatorTestCase', diff --git a/src/applications/files/PhabricatorImageTransformer.php b/src/applications/files/PhabricatorImageTransformer.php index 0ec46960cb..3273f84c50 100644 --- a/src/applications/files/PhabricatorImageTransformer.php +++ b/src/applications/files/PhabricatorImageTransformer.php @@ -104,7 +104,7 @@ final class PhabricatorImageTransformer { $x, $scaled_y); - return $this->saveImageDataInAnyFormat($img, $file->getMimeType()); + return self::saveImageDataInAnyFormat($img, $file->getMimeType()); } private function crasslyCropTo(PhabricatorFile $file, $top, $left, $w, $h) { @@ -126,7 +126,7 @@ final class PhabricatorImageTransformer { $w, $h, $orig_w, $orig_h); - return $this->saveImageDataInAnyFormat($dst, $file->getMimeType()); + return self::saveImageDataInAnyFormat($dst, $file->getMimeType()); } @@ -141,7 +141,7 @@ final class PhabricatorImageTransformer { } $dst = $this->applyScaleTo($file, $dx, $dy); - return $this->saveImageDataInAnyFormat($dst, $file->getMimeType()); + return self::saveImageDataInAnyFormat($dst, $file->getMimeType()); } private function getBlankDestinationFile($dx, $dy) { @@ -254,7 +254,7 @@ final class PhabricatorImageTransformer { $sdx, $sdy, $x, $y); - return $this->saveImageDataInAnyFormat($dst, $file->getMimeType()); + return self::saveImageDataInAnyFormat($dst, $file->getMimeType()); } private function applyMemeTo( @@ -314,7 +314,7 @@ final class PhabricatorImageTransformer { break; } } - return $this->saveImageDataInAnyFormat($img, $file->getMimeType()); + return self::saveImageDataInAnyFormat($img, $file->getMimeType()); } private function makeImageWithTextBorder($img, $font_size, $x, $y, @@ -352,7 +352,7 @@ final class PhabricatorImageTransformer { ); } - private function saveImageDataInAnyFormat($data, $preferred_mime = '') { + public static function saveImageDataInAnyFormat($data, $preferred_mime = '') { switch ($preferred_mime) { case 'image/gif': // Gif doesn't support true color case 'image/png': diff --git a/src/applications/lipsum/image/PhabricatorLipsumArtist.php b/src/applications/lipsum/image/PhabricatorLipsumArtist.php new file mode 100644 index 0000000000..695f1a2f63 --- /dev/null +++ b/src/applications/lipsum/image/PhabricatorLipsumArtist.php @@ -0,0 +1,68 @@ +draw($image, $x, $y); + return PhabricatorImageTransformer::saveImageDataInAnyFormat( + $image, + 'image/jpeg'); + } + + abstract protected function draw($image, $x, $y); + +} diff --git a/src/applications/lipsum/image/PhabricatorLipsumMondrianArtist.php b/src/applications/lipsum/image/PhabricatorLipsumMondrianArtist.php new file mode 100644 index 0000000000..39cb46a8a0 --- /dev/null +++ b/src/applications/lipsum/image/PhabricatorLipsumMondrianArtist.php @@ -0,0 +1,48 @@ +getHSBColor( + mt_rand(0, 359), + mt_rand(80, 100) / 100, + mt_rand(90, 100) / 100); + + imagefill($image, $xp, $yp, $c_fill); + } + } + +}