Dmitry
Dmitry

Reputation: 23

PHP GD .ico handling

Users of my PHP webapp are permitted to upload PNG and JPEG images. Upload algorithm is following:

  1. check extension by file name parsing
  2. check extension by getimagesize()
  3. recreate image by imagecreatefrompng()/imagepng() (imagecreatefromjpeg()/imagejpeg())
  4. rename image
  5. save to filesystem

Image recreation is used for security. Everything works fine. But now i need this algorithm to handle .ico files. It seems like GD doesn't work with .ico (there is no function like imagecreatefromico()), so i don`t know how to implement step 3 of my algorithm.

Thanks for any help or advice.

Upvotes: 2

Views: 1535

Answers (1)

Paul Dixon
Paul Dixon

Reputation: 300825

See https://github.com/lordelph/icofileloader for a composer-installable class which can load .ico files into a GD image.

For example:

$loader = new Elphin\IcoFileLoader\IcoFileService;
$im = $loader->extractIcon('/path/to/icon.ico', 32, 32);

See documentation for other methods of analysing and extracting images from the icon file.

Upvotes: 2

Related Questions