{"action":"created","comment":{"url":"https://api.github.com/repos/lbarulski/ImageStorage/pulls/comments/24981798","id":24981798,"diff_hunk":"@@ -0,0 +1,168 @@\n+<?php\n+namespace ImageStorage\\Image\\Transformation;\n+\n+class WatermarkRand implements \\ImageStorage\\Image\\Transformation\n+{\n+\t/**\n+\t * @var \\ImageStorage\\Image\\Structure\\Image\n+\t */\n+\tprivate $_imageStruct;\n+\n+\t/**\n+\t * @var \\ImageStorage\\Image\\Structure\\WatermarkRand|null\n+\t */\n+\tprivate $_watermarkRand = null;\n+\n+\t/**\n+\t * @param \\ImageStorage\\Image\\Structure\\WatermarkRand $watermark\n+\t *\n+\t * @throws \\Exception\n+\t */\n+\tpublic function __construct(\\ImageStorage\\Image\\Structure\\WatermarkRand $watermarkRand = null)\n+\t{\n+\t\tif (!($watermarkRand instanceof \\ImageStorage\\Image\\Structure\\WatermarkRand))\n+\t\t{\n+\t\t\tthrow new \\Exception('Bad structure!');\n+\t\t}\n+\n+\t\t$this->_watermarkRand = $watermarkRand;\n+\t}\n+\n+\t/**\n+\t * @param \\ImageStorage\\Image\\Structure\\Image $imageStruct\n+\t *\n+\t * @return \\ImageStorage\\Image\\Structure\\Image\n+\t */\n+\tpublic function transform(\\ImageStorage\\Image\\Structure\\Image $imageStruct)\n+\t{\n+\t\t$this->_imageStruct = $imageStruct;\n+\n+\t\treturn $this->_watermark_rand();\n+\t}\n+\n+\t/**\n+\t * @return \\ImageStorage\\Image\\Structure\\Image\n+\t * @throws \\Exception\n+\t */\n+\tprivate function _watermark_rand()\n+\t{\n+\t\tif (file_exists($this->_watermarkRand->fileName))\n+\t\t{\n+\n+\n+\t\t\t$config = $this->_watermarkRand;\n+\n+\n+\t\t\tif (class_exists('\\Imagick'))\n+\t\t\t{\n+\n+\n+\t\t\t\t//prepare source in Imagick\n+\t\t\t\t$source = new \\Imagick();\n+\t\t\t\t$source->readImageBlob($this->getPngBlobFromGd($this->_imageStruct->image));\n+\n+\t\t\t\t//prepare watermark\n+\t\t\t\t$watermark        = new \\Imagick($this->_watermarkRand->fileName);\n+\t\t\t\t$maxWatermarkSize = $source->getImageWidth() * $config->getSize();\n+\t\t\t\tif ($maxWatermarkSize < $config->getMinSize())\n+\t\t\t\t{\n+\t\t\t\t\t$maxWatermarkSize = $config->getMinSize();\n+\t\t\t\t}\n+\n+\t\t\t\t$watermark->thumbnailImage($maxWatermarkSize, $maxWatermarkSize);\n+\n+\t\t\t\t//cache image size\n+\t\t\t\t$imageWidth  = $source->getImageWidth();\n+\t\t\t\t$imageHeight = $source->getImageHeight();\n+\n+\t\t\t\t//set max watermarks\n+\t\t\t\t$maxCols = $imageWidth / $config->getMinSize() / 2;\n+\t\t\t\tif ($maxCols < $config->getCols())\n+\t\t\t\t{\n+\t\t\t\t\t$config->setCols(ceil($maxCols));\n+\t\t\t\t}\n+\n+\t\t\t\t$maxRows = $imageHeight / $config->getMinSize() / 2;\n+\t\t\t\tif ($maxRows < $config->getRows())\n+\t\t\t\t{\n+\t\t\t\t\t$config->setRows(ceil($maxRows));\n+\t\t\t\t}\n+\n+\n+\t\t\t\t//step width\n+\t\t\t\t$stepWidth  = $imageWidth / $config->getCols();\n+\t\t\t\t$stepHeight = $imageHeight / $config->getRows();\n+\n+\t\t\t\t//put images\n+\t\t\t\tfor ($row = 0; $row < $config->getRows(); $row++)\n+\t\t\t\t{\n+\t\t\t\t\tfor ($col = 0; $col < $config->getCols(); $col++)\n+\t\t\t\t\t{\n+\t\t\t\t\t\t$x = rand($col * $stepWidth, ($col + 1) * $stepWidth);\n+\t\t\t\t\t\t$y = rand($row * $stepHeight, ($row + 1) * $stepHeight);\n+\n+\t\t\t\t\t\t//make sure that watermark is in image bound\n+\t\t\t\t\t\tif (($x + $maxWatermarkSize) > $imageWidth)\n+\t\t\t\t\t\t{\n+\t\t\t\t\t\t\t$x = $imageWidth - $maxWatermarkSize;\n+\t\t\t\t\t\t}\n+\n+\t\t\t\t\t\tif (($y + $maxWatermarkSize) > $imageHeight)\n+\t\t\t\t\t\t{\n+\t\t\t\t\t\t\t$y = $imageHeight - $maxWatermarkSize;\n+\t\t\t\t\t\t}\n+\n+\t\t\t\t\t\t//put watermark to image\n+\t\t\t\t\t\t$source->compositeImage($watermark, \\Imagick::COMPOSITE_OVER, $x, $y);\n+\t\t\t\t\t}\n+\t\t\t\t}\n+\n+\n+\t\t\t\t//now put logo in right bottom corner\n+\n+\n+\n+\n+\t\t\t\t$logoUrl = dirname($this->_watermarkRand->fileName) . DIRECTORY_SEPARATOR . 'logo_'.c(\"LANGUAGE\").'.png';","path":"src/ImageStorage/Image/Transformation/WatermarkRand.php","position":126,"original_position":126,"commit_id":"b63e60a9b04c455bd0dc9017ddc5c1f7c7ab9bac","original_commit_id":"b63e60a9b04c455bd0dc9017ddc5c1f7c7ab9bac","user":{"login":"mlebkowski","id":848731,"avatar_url":"https://avatars.githubusercontent.com/u/848731?v=3","gravatar_id":"","url":"https://api.github.com/users/mlebkowski","html_url":"https://github.com/mlebkowski","followers_url":"https://api.github.com/users/mlebkowski/followers","following_url":"https://api.github.com/users/mlebkowski/following{/other_user}","gists_url":"https://api.github.com/users/mlebkowski/gists{/gist_id}","starred_url":"https://api.github.com/users/mlebkowski/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mlebkowski/subscriptions","organizations_url":"https://api.github.com/users/mlebkowski/orgs","repos_url":"https://api.github.com/users/mlebkowski/repos","events_url":"https://api.github.com/users/mlebkowski/events{/privacy}","received_events_url":"https://api.github.com/users/mlebkowski/received_events","type":"User","site_admin":false},"body":"`c` function is not defined","created_at":"2015-02-19T11:42:16Z","updated_at":"2015-02-19T11:42:16Z","html_url":"https://github.com/lbarulski/ImageStorage/pull/2#discussion_r24981798","pull_request_url":"https://api.github.com/repos/lbarulski/ImageStorage/pulls/2","_links":{"self":{"href":"https://api.github.com/repos/lbarulski/ImageStorage/pulls/comments/24981798"},"html":{"href":"https://github.com/lbarulski/ImageStorage/pull/2#discussion_r24981798"},"pull_request":{"href":"https://api.github.com/repos/lbarulski/ImageStorage/pulls/2"}}},"pull_request":{"url":"https://api.github.com/repos/lbarulski/ImageStorage/pulls/2","id":29601953,"html_url":"https://github.com/lbarulski/ImageStorage/pull/2","diff_url":"https://github.com/lbarulski/ImageStorage/pull/2.diff","patch_url":"https://github.com/lbarulski/ImageStorage/pull/2.patch","issue_url":"https://api.github.com/repos/lbarulski/ImageStorage/issues/2","number":2,"state":"closed","locked":false,"title":"add WatermarkRand","user":{"login":"mzeromskizl","id":10739163,"avatar_url":"https://avatars.githubusercontent.com/u/10739163?v=3","gravatar_id":"","url":"https://api.github.com/users/mzeromskizl","html_url":"https://github.com/mzeromskizl","followers_url":"https://api.github.com/users/mzeromskizl/followers","following_url":"https://api.github.com/users/mzeromskizl/following{/other_user}","gists_url":"https://api.github.com/users/mzeromskizl/gists{/gist_id}","starred_url":"https://api.github.com/users/mzeromskizl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mzeromskizl/subscriptions","organizations_url":"https://api.github.com/users/mzeromskizl/orgs","repos_url":"https://api.github.com/users/mzeromskizl/repos","events_url":"https://api.github.com/users/mzeromskizl/events{/privacy}","received_events_url":"https://api.github.com/users/mzeromskizl/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-02-19T10:57:11Z","updated_at":"2015-02-19T11:42:16Z","closed_at":"2015-02-19T11:23:53Z","merged_at":"2015-02-19T11:23:53Z","merge_commit_sha":"0e11b189116fc3708e7018b7bed3cf0e355e92b9","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/lbarulski/ImageStorage/pulls/2/commits","review_comments_url":"https://api.github.com/repos/lbarulski/ImageStorage/pulls/2/comments","review_comment_url":"https://api.github.com/repos/lbarulski/ImageStorage/pulls/comments/{number}","comments_url":"https://api.github.com/repos/lbarulski/ImageStorage/issues/2/comments","statuses_url":"https://api.github.com/repos/lbarulski/ImageStorage/statuses/b63e60a9b04c455bd0dc9017ddc5c1f7c7ab9bac","head":{"label":"feature/WatermarkRand","ref":"feature/WatermarkRand","sha":"b63e60a9b04c455bd0dc9017ddc5c1f7c7ab9bac","user":{"login":"lbarulski","id":2803144,"avatar_url":"https://avatars.githubusercontent.com/u/2803144?v=3","gravatar_id":"","url":"https://api.github.com/users/lbarulski","html_url":"https://github.com/lbarulski","followers_url":"https://api.github.com/users/lbarulski/followers","following_url":"https://api.github.com/users/lbarulski/following{/other_user}","gists_url":"https://api.github.com/users/lbarulski/gists{/gist_id}","starred_url":"https://api.github.com/users/lbarulski/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lbarulski/subscriptions","organizations_url":"https://api.github.com/users/lbarulski/orgs","repos_url":"https://api.github.com/users/lbarulski/repos","events_url":"https://api.github.com/users/lbarulski/events{/privacy}","received_events_url":"https://api.github.com/users/lbarulski/received_events","type":"User","site_admin":false},"repo":{"id":7621759,"name":"ImageStorage","full_name":"lbarulski/ImageStorage","owner":{"login":"lbarulski","id":2803144,"avatar_url":"https://avatars.githubusercontent.com/u/2803144?v=3","gravatar_id":"","url":"https://api.github.com/users/lbarulski","html_url":"https://github.com/lbarulski","followers_url":"https://api.github.com/users/lbarulski/followers","following_url":"https://api.github.com/users/lbarulski/following{/other_user}","gists_url":"https://api.github.com/users/lbarulski/gists{/gist_id}","starred_url":"https://api.github.com/users/lbarulski/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lbarulski/subscriptions","organizations_url":"https://api.github.com/users/lbarulski/orgs","repos_url":"https://api.github.com/users/lbarulski/repos","events_url":"https://api.github.com/users/lbarulski/events{/privacy}","received_events_url":"https://api.github.com/users/lbarulski/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/lbarulski/ImageStorage","description":"","fork":false,"url":"https://api.github.com/repos/lbarulski/ImageStorage","forks_url":"https://api.github.com/repos/lbarulski/ImageStorage/forks","keys_url":"https://api.github.com/repos/lbarulski/ImageStorage/keys{/key_id}","collaborators_url":"https://api.github.com/repos/lbarulski/ImageStorage/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/lbarulski/ImageStorage/teams","hooks_url":"https://api.github.com/repos/lbarulski/ImageStorage/hooks","issue_events_url":"https://api.github.com/repos/lbarulski/ImageStorage/issues/events{/number}","events_url":"https://api.github.com/repos/lbarulski/ImageStorage/events","assignees_url":"https://api.github.com/repos/lbarulski/ImageStorage/assignees{/user}","branches_url":"https://api.github.com/repos/lbarulski/ImageStorage/branches{/branch}","tags_url":"https://api.github.com/repos/lbarulski/ImageStorage/tags","blobs_url":"https://api.github.com/repos/lbarulski/ImageStorage/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/lbarulski/ImageStorage/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/lbarulski/ImageStorage/git/refs{/sha}","trees_url":"https://api.github.com/repos/lbarulski/ImageStorage/git/trees{/sha}","statuses_url":"https://api.github.com/repos/lbarulski/ImageStorage/statuses/{sha}","languages_url":"https://api.github.com/repos/lbarulski/ImageStorage/languages","stargazers_url":"https://api.github.com/repos/lbarulski/ImageStorage/stargazers","contributors_url":"https://api.github.com/repos/lbarulski/ImageStorage/contributors","subscribers_url":"https://api.github.com/repos/lbarulski/ImageStorage/subscribers","subscription_url":"https://api.github.com/repos/lbarulski/ImageStorage/subscription","commits_url":"https://api.github.com/repos/lbarulski/ImageStorage/commits{/sha}","git_commits_url":"https://api.github.com/repos/lbarulski/ImageStorage/git/commits{/sha}","comments_url":"https://api.github.com/repos/lbarulski/ImageStorage/comments{/number}","issue_comment_url":"https://api.github.com/repos/lbarulski/ImageStorage/issues/comments/{number}","contents_url":"https://api.github.com/repos/lbarulski/ImageStorage/contents/{+path}","compare_url":"https://api.github.com/repos/lbarulski/ImageStorage/compare/{base}...{head}","merges_url":"https://api.github.com/repos/lbarulski/ImageStorage/merges","archive_url":"https://api.github.com/repos/lbarulski/ImageStorage/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/lbarulski/ImageStorage/downloads","issues_url":"https://api.github.com/repos/lbarulski/ImageStorage/issues{/number}","pulls_url":"https://api.github.com/repos/lbarulski/ImageStorage/pulls{/number}","milestones_url":"https://api.github.com/repos/lbarulski/ImageStorage/milestones{/number}","notifications_url":"https://api.github.com/repos/lbarulski/ImageStorage/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/lbarulski/ImageStorage/labels{/name}","releases_url":"https://api.github.com/repos/lbarulski/ImageStorage/releases{/id}","created_at":"2013-01-15T09:07:31Z","updated_at":"2015-02-19T11:27:45Z","pushed_at":"2015-02-19T11:27:14Z","git_url":"git://github.com/lbarulski/ImageStorage.git","ssh_url":"git@github.com:lbarulski/ImageStorage.git","clone_url":"https://github.com/lbarulski/ImageStorage.git","svn_url":"https://github.com/lbarulski/ImageStorage","homepage":null,"size":292,"stargazers_count":0,"watchers_count":0,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"master","ref":"master","sha":"8ef9709bcc3ecdcd0b6b78c20ba8802c4f0c69f7","user":{"login":"lbarulski","id":2803144,"avatar_url":"https://avatars.githubusercontent.com/u/2803144?v=3","gravatar_id":"","url":"https://api.github.com/users/lbarulski","html_url":"https://github.com/lbarulski","followers_url":"https://api.github.com/users/lbarulski/followers","following_url":"https://api.github.com/users/lbarulski/following{/other_user}","gists_url":"https://api.github.com/users/lbarulski/gists{/gist_id}","starred_url":"https://api.github.com/users/lbarulski/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lbarulski/subscriptions","organizations_url":"https://api.github.com/users/lbarulski/orgs","repos_url":"https://api.github.com/users/lbarulski/repos","events_url":"https://api.github.com/users/lbarulski/events{/privacy}","received_events_url":"https://api.github.com/users/lbarulski/received_events","type":"User","site_admin":false},"repo":{"id":7621759,"name":"ImageStorage","full_name":"lbarulski/ImageStorage","owner":{"login":"lbarulski","id":2803144,"avatar_url":"https://avatars.githubusercontent.com/u/2803144?v=3","gravatar_id":"","url":"https://api.github.com/users/lbarulski","html_url":"https://github.com/lbarulski","followers_url":"https://api.github.com/users/lbarulski/followers","following_url":"https://api.github.com/users/lbarulski/following{/other_user}","gists_url":"https://api.github.com/users/lbarulski/gists{/gist_id}","starred_url":"https://api.github.com/users/lbarulski/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lbarulski/subscriptions","organizations_url":"https://api.github.com/users/lbarulski/orgs","repos_url":"https://api.github.com/users/lbarulski/repos","events_url":"https://api.github.com/users/lbarulski/events{/privacy}","received_events_url":"https://api.github.com/users/lbarulski/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/lbarulski/ImageStorage","description":"","fork":false,"url":"https://api.github.com/repos/lbarulski/ImageStorage","forks_url":"https://api.github.com/repos/lbarulski/ImageStorage/forks","keys_url":"https://api.github.com/repos/lbarulski/ImageStorage/keys{/key_id}","collaborators_url":"https://api.github.com/repos/lbarulski/ImageStorage/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/lbarulski/ImageStorage/teams","hooks_url":"https://api.github.com/repos/lbarulski/ImageStorage/hooks","issue_events_url":"https://api.github.com/repos/lbarulski/ImageStorage/issues/events{/number}","events_url":"https://api.github.com/repos/lbarulski/ImageStorage/events","assignees_url":"https://api.github.com/repos/lbarulski/ImageStorage/assignees{/user}","branches_url":"https://api.github.com/repos/lbarulski/ImageStorage/branches{/branch}","tags_url":"https://api.github.com/repos/lbarulski/ImageStorage/tags","blobs_url":"https://api.github.com/repos/lbarulski/ImageStorage/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/lbarulski/ImageStorage/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/lbarulski/ImageStorage/git/refs{/sha}","trees_url":"https://api.github.com/repos/lbarulski/ImageStorage/git/trees{/sha}","statuses_url":"https://api.github.com/repos/lbarulski/ImageStorage/statuses/{sha}","languages_url":"https://api.github.com/repos/lbarulski/ImageStorage/languages","stargazers_url":"https://api.github.com/repos/lbarulski/ImageStorage/stargazers","contributors_url":"https://api.github.com/repos/lbarulski/ImageStorage/contributors","subscribers_url":"https://api.github.com/repos/lbarulski/ImageStorage/subscribers","subscription_url":"https://api.github.com/repos/lbarulski/ImageStorage/subscription","commits_url":"https://api.github.com/repos/lbarulski/ImageStorage/commits{/sha}","git_commits_url":"https://api.github.com/repos/lbarulski/ImageStorage/git/commits{/sha}","comments_url":"https://api.github.com/repos/lbarulski/ImageStorage/comments{/number}","issue_comment_url":"https://api.github.com/repos/lbarulski/ImageStorage/issues/comments/{number}","contents_url":"https://api.github.com/repos/lbarulski/ImageStorage/contents/{+path}","compare_url":"https://api.github.com/repos/lbarulski/ImageStorage/compare/{base}...{head}","merges_url":"https://api.github.com/repos/lbarulski/ImageStorage/merges","archive_url":"https://api.github.com/repos/lbarulski/ImageStorage/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/lbarulski/ImageStorage/downloads","issues_url":"https://api.github.com/repos/lbarulski/ImageStorage/issues{/number}","pulls_url":"https://api.github.com/repos/lbarulski/ImageStorage/pulls{/number}","milestones_url":"https://api.github.com/repos/lbarulski/ImageStorage/milestones{/number}","notifications_url":"https://api.github.com/repos/lbarulski/ImageStorage/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/lbarulski/ImageStorage/labels{/name}","releases_url":"https://api.github.com/repos/lbarulski/ImageStorage/releases{/id}","created_at":"2013-01-15T09:07:31Z","updated_at":"2015-02-19T11:27:45Z","pushed_at":"2015-02-19T11:27:14Z","git_url":"git://github.com/lbarulski/ImageStorage.git","ssh_url":"git@github.com:lbarulski/ImageStorage.git","clone_url":"https://github.com/lbarulski/ImageStorage.git","svn_url":"https://github.com/lbarulski/ImageStorage","homepage":null,"size":292,"stargazers_count":0,"watchers_count":0,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/lbarulski/ImageStorage/pulls/2"},"html":{"href":"https://github.com/lbarulski/ImageStorage/pull/2"},"issue":{"href":"https://api.github.com/repos/lbarulski/ImageStorage/issues/2"},"comments":{"href":"https://api.github.com/repos/lbarulski/ImageStorage/issues/2/comments"},"review_comments":{"href":"https://api.github.com/repos/lbarulski/ImageStorage/pulls/2/comments"},"review_comment":{"href":"https://api.github.com/repos/lbarulski/ImageStorage/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/lbarulski/ImageStorage/pulls/2/commits"},"statuses":{"href":"https://api.github.com/repos/lbarulski/ImageStorage/statuses/b63e60a9b04c455bd0dc9017ddc5c1f7c7ab9bac"}}}}