Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Render function #14

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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' );

$source = dirname( __FILE__ ) . '/example.gif';

$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
Expand Down
18 changes: 18 additions & 0 deletions class-php-ico.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down