Skip to content

Instantly share code, notes, and snippets.

@ziadoz
Created March 4, 2020 18:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ziadoz/a4a168ac83d194ce827c0e328ceebb7e to your computer and use it in GitHub Desktop.
Save ziadoz/a4a168ac83d194ce827c0e328ceebb7e to your computer and use it in GitHub Desktop.
Extract PNG Images From Favicon ICO Images in PHP Using ImageMagick
<?php
// Extract favicon images from file path.
$faviconFile = __DIR__ . '/bbc.ico'
file_put_contents($faviconFile, file_get_contents('https://www.bbc.co.uk/favicon.ico'));
$imagick = new Imagick();
$imagick->readImage($faviconFile);
$imagick->writeImages(__DIR__ . '/bbc-extracted.png', false);
// Extract favicon images from string.
$imagick = new Imagick();
$imagick->setFormat('ICO');
$imagick->readImageBlob(file_get_contents('https://www.bbc.co.uk/favicon.ico'));
$imagick->writeImages(__DIR__ . '/bbc-extracted.png', false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment