From b5b00426d0c313bb84467b9b2634ca14d43edb8f Mon Sep 17 00:00:00 2001 From: David <32897194+gloony@users.noreply.github.com> Date: Mon, 4 Nov 2019 22:32:53 +0100 Subject: [PATCH 1/3] Add Render function If you don't want to save the file, this can be usefull --- class-php-ico.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/class-php-ico.php b/class-php-ico.php index 2e9983e..edfd67f 100644 --- a/class-php-ico.php +++ b/class-php-ico.php @@ -136,6 +136,24 @@ function save_ico( $file ) { return true; } + /** + * Display the ICO file data. + * + * @return boolean true on success and false on failure. + */ + function render_ico() { + if ( ! $this->_has_requirements ) + return false; + + if ( false === ( $data = $this->_get_ico_data() ) ) + return false; + + header('Content-Type: image/x-icon'); + echo $data; + + return true; + } + /** * Generate the final ICO data by creating a file header and adding the image data. * From 9d5df8a4d97ed918172e4ff0dac4b4b31ed657e0 Mon Sep 17 00:00:00 2001 From: David <32897194+gloony@users.noreply.github.com> Date: Mon, 4 Nov 2019 22:38:21 +0100 Subject: [PATCH 2/3] Update README.md Add rendering exemple --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index da0be75..3375bee 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,17 @@ $ico_lib->save_ico( $destination ); It takes a source file named `example.gif` and produce an output ICO file named `example.ico`. `example.ico` will contain a single image that is the same size as the source image. +You can also render the gif directly on the browser without saving it on the server: + +```php +require( dirname( __FILE__ ) . '/class-php-ico.php' ); + +$destination = dirname( __FILE__ ) . '/example.ico'; + +$ico_lib = new PHP_ICO( $source ); +$ico_lib->render_ico(); +```` + The ICO file format is capable of holding multiple images, each of a different size. The PHP ICO library opens up this feature of the ICO format as shown in the following example: ```php From 56ca042c50e27c02b6dfe2c562614c322cf59f10 Mon Sep 17 00:00:00 2001 From: David <32897194+gloony@users.noreply.github.com> Date: Mon, 4 Nov 2019 22:38:52 +0100 Subject: [PATCH 3/3] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3375bee..52f7d83 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ You can also render the gif directly on the browser without saving it on the ser ```php require( dirname( __FILE__ ) . '/class-php-ico.php' ); -$destination = dirname( __FILE__ ) . '/example.ico'; +$source = dirname( __FILE__ ) . '/example.gif'; $ico_lib = new PHP_ICO( $source ); $ico_lib->render_ico();