Merge pull request #6460 from nextcloud/theming-favicon-generated-sizes
Theming: Generate different favicon sizes
This commit is contained in:
commit
26bcf40e9e
|
@ -5,7 +5,7 @@
|
||||||
<description>Adjust the Nextcloud theme</description>
|
<description>Adjust the Nextcloud theme</description>
|
||||||
<licence>AGPL</licence>
|
<licence>AGPL</licence>
|
||||||
<author>Nextcloud</author>
|
<author>Nextcloud</author>
|
||||||
<version>1.4.0</version>
|
<version>1.4.1</version>
|
||||||
<namespace>Theming</namespace>
|
<namespace>Theming</namespace>
|
||||||
<category>other</category>
|
<category>other</category>
|
||||||
|
|
||||||
|
|
|
@ -55,14 +55,38 @@ class IconBuilder {
|
||||||
* @return string|false image blob
|
* @return string|false image blob
|
||||||
*/
|
*/
|
||||||
public function getFavicon($app) {
|
public function getFavicon($app) {
|
||||||
|
if (!$this->themingDefaults->shouldReplaceIcons()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
$icon = $this->renderAppIcon($app, 32);
|
$favicon = new Imagick();
|
||||||
|
$favicon->setFormat("ico");
|
||||||
|
$icon = $this->renderAppIcon($app, 128);
|
||||||
if ($icon === false) {
|
if ($icon === false) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$icon->setImageFormat("png32");
|
$icon->setImageFormat("png32");
|
||||||
$data = $icon->getImageBlob();
|
|
||||||
|
$clone = clone $icon;
|
||||||
|
$clone->scaleImage(16,0);
|
||||||
|
$favicon->addImage($clone);
|
||||||
|
|
||||||
|
$clone = clone $icon;
|
||||||
|
$clone->scaleImage(32,0);
|
||||||
|
$favicon->addImage($clone);
|
||||||
|
|
||||||
|
$clone = clone $icon;
|
||||||
|
$clone->scaleImage(64,0);
|
||||||
|
$favicon->addImage($clone);
|
||||||
|
|
||||||
|
$clone = clone $icon;
|
||||||
|
$clone->scaleImage(128,0);
|
||||||
|
$favicon->addImage($clone);
|
||||||
|
|
||||||
|
$data = $favicon->getImagesBlob();
|
||||||
|
$favicon->destroy();
|
||||||
$icon->destroy();
|
$icon->destroy();
|
||||||
|
$clone->destroy();
|
||||||
return $data;
|
return $data;
|
||||||
} catch (\ImagickException $e) {
|
} catch (\ImagickException $e) {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -71,6 +71,9 @@ class IconBuilderTest extends TestCase {
|
||||||
if (count($checkImagick->queryFormats('SVG')) < 1) {
|
if (count($checkImagick->queryFormats('SVG')) < 1) {
|
||||||
$this->markTestSkipped('No SVG provider present.');
|
$this->markTestSkipped('No SVG provider present.');
|
||||||
}
|
}
|
||||||
|
if (count($checkImagick->queryFormats('PNG')) < 1) {
|
||||||
|
$this->markTestSkipped('No PNG provider present.');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function dataRenderAppIcon() {
|
public function dataRenderAppIcon() {
|
||||||
|
@ -146,17 +149,23 @@ class IconBuilderTest extends TestCase {
|
||||||
*/
|
*/
|
||||||
public function testGetFavicon($app, $color, $file) {
|
public function testGetFavicon($app, $color, $file) {
|
||||||
$this->checkImagick();
|
$this->checkImagick();
|
||||||
|
$this->themingDefaults->expects($this->once())
|
||||||
|
->method('shouldReplaceIcons')
|
||||||
|
->willReturn(true);
|
||||||
$this->themingDefaults->expects($this->once())
|
$this->themingDefaults->expects($this->once())
|
||||||
->method('getColorPrimary')
|
->method('getColorPrimary')
|
||||||
->willReturn($color);
|
->willReturn($color);
|
||||||
|
|
||||||
$expectedIcon = new \Imagick(realpath(dirname(__FILE__)). "/data/" . $file);
|
$expectedIcon = new \Imagick(realpath(dirname(__FILE__)). "/data/" . $file);
|
||||||
|
$actualIcon = $this->iconBuilder->getFavicon($app);
|
||||||
|
|
||||||
$icon = new \Imagick();
|
$icon = new \Imagick();
|
||||||
$icon->readImageBlob($this->iconBuilder->getFavicon($app));
|
$icon->setFormat('ico');
|
||||||
|
$icon->readImageBlob($actualIcon);
|
||||||
|
|
||||||
$this->assertEquals(true, $icon->valid());
|
$this->assertEquals(true, $icon->valid());
|
||||||
$this->assertEquals(32, $icon->getImageWidth());
|
$this->assertEquals(128, $icon->getImageWidth());
|
||||||
$this->assertEquals(32, $icon->getImageHeight());
|
$this->assertEquals(128, $icon->getImageHeight());
|
||||||
$icon->destroy();
|
$icon->destroy();
|
||||||
$expectedIcon->destroy();
|
$expectedIcon->destroy();
|
||||||
// FIXME: We may need some comparison of the generated and the test images
|
// FIXME: We may need some comparison of the generated and the test images
|
||||||
|
@ -167,8 +176,12 @@ class IconBuilderTest extends TestCase {
|
||||||
* @expectedException \PHPUnit_Framework_Error_Warning
|
* @expectedException \PHPUnit_Framework_Error_Warning
|
||||||
*/
|
*/
|
||||||
public function testGetFaviconNotFound() {
|
public function testGetFaviconNotFound() {
|
||||||
|
$this->checkImagick();
|
||||||
$util = $this->getMockBuilder(Util::class)->disableOriginalConstructor()->getMock();
|
$util = $this->getMockBuilder(Util::class)->disableOriginalConstructor()->getMock();
|
||||||
$iconBuilder = new IconBuilder($this->themingDefaults, $util);
|
$iconBuilder = new IconBuilder($this->themingDefaults, $util);
|
||||||
|
$this->themingDefaults->expects($this->once())
|
||||||
|
->method('shouldReplaceIcons')
|
||||||
|
->willReturn(true);
|
||||||
$util->expects($this->once())
|
$util->expects($this->once())
|
||||||
->method('getAppIcon')
|
->method('getAppIcon')
|
||||||
->willReturn('notexistingfile');
|
->willReturn('notexistingfile');
|
||||||
|
@ -179,6 +192,7 @@ class IconBuilderTest extends TestCase {
|
||||||
* @expectedException \PHPUnit_Framework_Error_Warning
|
* @expectedException \PHPUnit_Framework_Error_Warning
|
||||||
*/
|
*/
|
||||||
public function testGetTouchIconNotFound() {
|
public function testGetTouchIconNotFound() {
|
||||||
|
$this->checkImagick();
|
||||||
$util = $this->getMockBuilder(Util::class)->disableOriginalConstructor()->getMock();
|
$util = $this->getMockBuilder(Util::class)->disableOriginalConstructor()->getMock();
|
||||||
$iconBuilder = new IconBuilder($this->themingDefaults, $util);
|
$iconBuilder = new IconBuilder($this->themingDefaults, $util);
|
||||||
$util->expects($this->once())
|
$util->expects($this->once())
|
||||||
|
@ -191,6 +205,7 @@ class IconBuilderTest extends TestCase {
|
||||||
* @expectedException \PHPUnit_Framework_Error_Warning
|
* @expectedException \PHPUnit_Framework_Error_Warning
|
||||||
*/
|
*/
|
||||||
public function testColorSvgNotFound() {
|
public function testColorSvgNotFound() {
|
||||||
|
$this->checkImagick();
|
||||||
$util = $this->getMockBuilder(Util::class)->disableOriginalConstructor()->getMock();
|
$util = $this->getMockBuilder(Util::class)->disableOriginalConstructor()->getMock();
|
||||||
$iconBuilder = new IconBuilder($this->themingDefaults, $util);
|
$iconBuilder = new IconBuilder($this->themingDefaults, $util);
|
||||||
$util->expects($this->once())
|
$util->expects($this->once())
|
||||||
|
|
Loading…
Reference in New Issue