Skip to content

Commit

Permalink
Use IcoFileLoader instead of floIcon
Browse files Browse the repository at this point in the history
  • Loading branch information
jtojnar committed May 15, 2017
1 parent 1d982a4 commit d130757
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 855 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ Special thanks to the great programmers of this libraries which will be used in
* htmLawed: http://www.bioinformatics.org/phplabware/internal_utilities/htmLawed/
* PHP Universal Feed Generator: https://github.com/ajaxray/FeedWriter
* twitteroauth: https://github.com/abraham/twitteroauth
* floIcon: https://www.phpclasses.org/package/3906-PHP-Read-and-write-images-from-ICO-files.html
* Elphin IcoFileLoader: https://github.com/lordelph/icofileloader
* jQuery hotkeys: https://github.com/tzuryby/jquery.hotkeys
* jsmin: https://github.com/rgrove/jsmin-php
* cssmin: https://code.google.com/archive/p/cssmin
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"htmlawed/htmlawed": "^1.1",
"j0k3r/graby": "^1.6",
"linkorb/jsmin-php": "^1.0",
"lordelph/icofileloader": "^1.0",
"mibe/feedwriter": "^1.0",
"monolog/monolog": "^1.0",
"natxet/CssMin": "^3.0",
Expand All @@ -30,7 +31,6 @@
"controllers/",
"daos/",
"helpers/",
"libs/",
"spouts/"
]
},
Expand Down
53 changes: 52 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ function isNotUnimportant(dest) {

const filenameDisallowed = [
/^changelog/i,
/^contributing/i,
/^copying/i,
/^readme/i,
/^licen[cs]e/i,
Expand Down Expand Up @@ -85,7 +86,6 @@ module.exports = function(grunt) {
{ expand: true, cwd: 'controllers/', src: ['**'], dest: '/controllers'},
{ expand: true, cwd: 'daos/', src: ['**'], dest: '/daos'},
{ expand: true, cwd: 'helpers/', src: ['**'], dest: '/helpers'},
{ expand: true, cwd: 'libs/', src: ['**'], dest: '/libs'},
{ expand: true, cwd: 'vendor/', src: ['**'], dest: '/vendor', filter: isNotUnimportant},

// public = don't zip all.js and all.css
Expand Down
31 changes: 23 additions & 8 deletions helpers/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace helpers;

use Elphin\IcoFileLoader\IcoFileService;
use WideImage\WideImage;

/**
Expand Down Expand Up @@ -116,28 +117,42 @@ public function loadImage($url, $extension = 'png', $width = false, $height = fa
} elseif (strtolower($imgInfo['mime']) == 'image/x-ms-bmp') {
$type = 'bmp';
} else {
@unlink($tmp);

return false;
}

// convert ico to png
if ($type == 'ico') {
$ico = new \floIcon();
@$ico->readICO($tmp);
if (count($ico->images) == 0) {
@unlink($tmp);
$loader = new IcoFileService();
try {
$icon = $loader->fromString($data);
} catch (\InvalidArgumentException $e) {
\F3::get('logger')->error("Icon “{$url}” is not valid", ['exception' => $e]);

return false;
}

$image = null;
if ($width !== false && $height !== false) {
$image = $icon->findBestForSize($width, $height);
}

if ($image === null) {
$image = $icon->findBest();
}

if ($image === null) {
return false;
}

$data = $loader->renderImage($image);

ob_start();
@imagepng($ico->images[count($ico->images) - 1]->getImageResource());
imagepng($data);
$data = ob_get_contents();
ob_end_clean();
}

// parse image for saving it later
@unlink($tmp);
try {
$wideImage = WideImage::load($data);
} catch (\Exception $e) {
Expand Down
Loading

0 comments on commit d130757

Please sign in to comment.