Giter Club home page Giter Club logo

icofileloader's People

Contributors

jtojnar avatar lordelph avatar scrutinizer-auto-fixer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

icofileloader's Issues

Extract all icons in a web link

Hi

Right now it seam as if it is only possible to get individual images in an ico file when it is placed locally as a file (fromFile or from). I like to get it from a remote url. So I guess that I have to retrieve the file first and store it locally.

Nice to have it as a single function like with extractIcon?

/Benny

Carefully crafted ICO can trigger a fatal error

I ran into a situation with an ico image where IcoParser->isPNG($data) passed, but then imagecreatefromstring($data) failed. The result is that in parsePNGAsIco() it crashes with a fatal error when it gets to the imagesx(false) line. Here is the bug fix:

private function parsePNGAsIco($data)
    {
        $png = imagecreatefromstring($data);
+       if (!$png) {
+           throw new \InvalidArgumentException('Invalid PNG file format');
+       }
        $w = imagesx($png);
        $h = imagesy($png);

Here is the icon that triggered the error for me.
favicon.ico.zip

Upgrade to imagecreatefrombmp

From the readme:

The current GdRenderer works by drawing individual pixels for BMP based icon images. This isn't going to be terribly fast. PHP 7.2 will have support for BMP images, and I'll add a renderer which takes advantage of that when it is released.

Just reminding you that this is possible now with imagecreatefrombmp and it would be great to get this update. Thanks for maintaining this library.

Invalid PNG metadata when ICONDIRENTRY has a bitCount of zero

Thank you for this little libray. I face an issue with a specific icon which has mixed BMP and PNG images. In this case it's a 256x256 PNG contained in ResourceHacker's main executable:
http://angusj.com/resourcehacker/

If an icon contains a PNG image and in ICONDIRENTRY the PNG's bitCount is set to zero the value in IconImage is not updated to the PNG's real bit depth.

How to reproduce:

$service = new IcoFileService();
$icon = $service->from(file_get_contents('http://rosasurfer.com/.intern/mixed.ico'));
/** @var IconImage $image */
foreach ($icon as $image) {
    echo $image->getDescription().PHP_EOL;
}

Expected result:

256x256 pixel PNG @ 32 bits/pixel
64x64 pixel BMP @ 32 bits/pixel
48x48 pixel BMP @ 32 bits/pixel
40x40 pixel BMP @ 32 bits/pixel
32x32 pixel BMP @ 32 bits/pixel
24x24 pixel BMP @ 32 bits/pixel
20x20 pixel BMP @ 32 bits/pixel
16x16 pixel BMP @ 32 bits/pixel

Actual result:

256x256 pixel PNG @ 0 bits/pixel
64x64 pixel BMP @ 32 bits/pixel
48x48 pixel BMP @ 32 bits/pixel
40x40 pixel BMP @ 32 bits/pixel
32x32 pixel BMP @ 32 bits/pixel
24x24 pixel BMP @ 32 bits/pixel
20x20 pixel BMP @ 32 bits/pixel
16x16 pixel BMP @ 32 bits/pixel

I worked around it by adding the following snippet to IconParser::parseIconDirEntries() but I don't know the header format good enough and suspect I break cases where a bitCount of zero has a different valid meaning.

if ($icoDirEntry['bitCount'] == 0) {
    $icoDirEntry['bitCount'] = 32;
}

Wouldn't it be better to parse the actual PNG header instead of using possibly conflicting ICONDIRENTRY values? I use this little library which only needs to read the first 29 bytes of a PNG:
https://github.com/ktomk/Miscellaneous/tree/master/get_png_imageinfo

Another note: All internal parser methods are private and there is no way to re-use your class. Can you consider making them protected?

Thank you again.

Support loading PNG as if it was an ICO file

Having seen some favicon.ico files delivered with a MIME type of image/x-icon or image/vnd.microsoft.icon, I think the parser should cope, particular as it copes with PNG properly embedded in an icon.

Here's an example (from sciencedirect.com)

# fetch 'ico' file, get proper MIME type...
$ curl -O -v http://cdn.els-cdn.com/sd/favSD.ico
> GET /sd/favSD.ico HTTP/1.1
(snip)
< Content-Type: image/x-icon

#..and yet it is a PNG
$ hexdump -C -n128 favSD.ico 
00000000  89 50 4e 47 0d 0a 1a 0a  00 00 00 0d 49 48 44 52  |.PNG........IHDR|
00000010  00 00 00 10 00 00 00 10  08 03 00 00 00 28 2d 0f  |.............(-.|
00000020  53 00 00 00 04 67 41 4d  41 00 00 b1 8f 0b fc 61  |S....gAMA......a|
00000030  05 00 00 00 20 63 48 52  4d 00 00 7a 26 00 00 80  |.... cHRM..z&...|
00000040  84 00 00 fa 00 00 00 80  e8 00 00 75 30 00 00 ea  |...........u0...|
00000050  60 00 00 3a 98 00 00 17  70 9c ba 51 3c 00 00 01  |`..:....p..Q<...|
00000060  62 50 4c 54 45 f5 82 20  00 00 00 f5 82 20 f5 82  |bPLTE.. ..... ..|
00000070  20 f5 82 20 f5 82 20 f5  82 20 f5 82 20 f5 82 20  | .. .. .. .. .. |

PHP 8.1 Compatibility

I am upgrading my project to PHP 8.1 and am encountering warnings in your library. Here is one example:

Deprecated: Return type of Elphin\IcoFileLoader\Icon::offsetExists($offset) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice

The rest of the warnings are similar. The quick fix is to add the return types to the functions in question. Here are my changes. Hope this helps!
Icon.php.zip

PHP 8.2 issues: Implicit conversion from float and Uninitialized string offset 176

Hi,

Thanks for keeping this project up to date. It's very ussefut to my 21-year-old https://ukfree.tv

I'm getting, on PHP 8.2.8 the following two "stop" error messages

  • Uninitialized string offset 176 at line 204 of vendor/lordelph/icofileloader/src/GdRenderer.php
  • Implicit conversion from float 3289.5 to int loses precision on line 210 vendor/lordelph/icofileloader/src/IcoParser.php

I did a "composer bump" to get the most recent versions of code. 3.0.0.

"errline": 210, "backtrace": [ { "file": "IcoParser.php", "line": 210, "function": "substr", "class": "", "type": "" }, { "file": "IcoParser.php", "line": 178, "function": "parsePaletteImageData", "class": "Elphin\\IcoFileLoader\\IcoParser", "type": "->" }, { "file": "IcoParser.php", "line": 78, "function": "parseBmp", "class": "Elphin\\IcoFileLoader\\IcoParser", "type": "->" }

"errline": 225, "backtrace": [ { "file": "GdRenderer.php", "line": 93, "function": "render8bit", "class": "Elphin\\IcoFileLoader\\GdRenderer", "type": "->" }, { "file": "GdRenderer.php", "line": 19, "function": "renderBmpImage", "class": "Elphin\\IcoFileLoader\\GdRenderer", "type": "->" }, { "file": "IcoFileService.php", "line": 93, "function": "render", "class": "Elphin\\IcoFileLoader\\GdRenderer", "type": "->" } ],

Thanks,

Getting some warnings

Hi, thanks for this great library.
I'm getting some repetitive errors with some icons. Each time a icon fails, I get the following 5 warnings consecutively:

PHP Warning:  unpack(): Type L: not enough input, need 4, have 3 in .../vendor/lordelph/icofileloader/src/IcoParser.php on line 43
PHP Notice:  Trying to access array offset on value of type bool in .../vendor/lordelph/icofileloader/src/IcoParser.php on line 44
PHP Warning:  unpack(): Type S: not enough input, need 2, have 1 in .../vendor/lordelph/icofileloader/src/IcoParser.php on line 30
PHP Notice:  Trying to access array offset on value of type bool in .../vendor/lordelph/icofileloader/src/IcoParser.php on line 31
PHP Notice:  Trying to access array offset on value of type bool in .../vendor/lordelph/icofileloader/src/IcoParser.php on line 31

Maybe adding some conditions to avoid these errors or silence them with @ and throw an exception would be very helpful.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.