Move sizing to renderAppIcon method

Signed-off-by: Julius Haertl <jus@bitgrid.net>
This commit is contained in:
Julius Haertl 2016-12-04 13:02:17 +01:00
parent db56df1893
commit 797e761492
No known key found for this signature in database
GPG Key ID: 4C614C6ED2CDE6DF
2 changed files with 7 additions and 6 deletions

View File

@ -52,11 +52,10 @@ class IconBuilder {
* @return string|false image blob
*/
public function getFavicon($app) {
$icon = $this->renderAppIcon($app);
$icon = $this->renderAppIcon($app, 32);
if($icon === false) {
return false;
}
$icon->resizeImage(32, 32, Imagick::FILTER_LANCZOS, 1);
$icon->setImageFormat("png24");
$data = $icon->getImageBlob();
$icon->destroy();
@ -68,7 +67,7 @@ class IconBuilder {
* @return string|false image blob
*/
public function getTouchIcon($app) {
$icon = $this->renderAppIcon($app);
$icon = $this->renderAppIcon($app, 512);
if($icon === false) {
return false;
}
@ -83,9 +82,10 @@ class IconBuilder {
* fallback to logo
*
* @param $app string app name
* @param $size int size of the icon in px
* @return Imagick|false
*/
public function renderAppIcon($app) {
public function renderAppIcon($app, $size) {
try {
$appIcon = $this->util->getAppIcon($app);
$appIconContent = file_get_contents($appIcon);
@ -157,7 +157,8 @@ class IconBuilder {
$finalIconFile->setImageVirtualPixelMethod(Imagick::VIRTUALPIXELMETHOD_TRANSPARENT);
$finalIconFile->setImageArtifact('compose:args', "1,0,-0.5,0.5");
$finalIconFile->compositeImage($appIconFile, Imagick::COMPOSITE_ATOP, $offset_w, $offset_h);
$finalIconFile->resizeImage(512, 512, Imagick::FILTER_LANCZOS, 1);
$finalIconFile->setImageFormat('png24');
$finalIconFile->resizeImage($size, $size, Imagick::INTERPOLATE_BICUBIC, 1, false);
$appIconFile->destroy();
return $finalIconFile;

View File

@ -91,7 +91,7 @@ class IconBuilderTest extends TestCase {
->willReturn($color);
$expectedIcon = new \Imagick(realpath(dirname(__FILE__)). "/data/" . $file);
$icon = $this->iconBuilder->renderAppIcon($app);
$icon = $this->iconBuilder->renderAppIcon($app, 512);
$this->assertEquals(true, $icon->valid());
$this->assertEquals(512, $icon->getImageWidth());