PHP 8.5.0 Alpha 4 available for testing

Voting

: min(one, one)?
(Example: nine)

The Note You're Voting On

andyearnshaw at do-not-spam-mygmail dot com
12 years ago
If you try and load an ICO file whose extension isn't .ico, you'll get an error going along the lines of no delegate existing for the supplied image's format. The can occur, for example, if you're using a temporary file.

<?php
$tmp
= tempnam('cache/images', 'ico_');

if (
copy('http://remote.url/favicon.ico', $tmp)) {
$ico = new Imagick($tmp); // <-- ERROR!
}
?>

Your first thought might be to rename your temporary file's extension to .ico, but I decided to try something that works on the command line―prefix the file name with 'ico:'

<?php
$tmp
= tempnam('cache/images', 'ico_');

if (
copy('http://remote.url/favicon.ico', $tmp)) {
$ico = new Imagick("ico:$tmp"); // <-- Works great!
}
?>

<< Back to user notes page

To Top