Skip to content

Commit 3ef0454

Browse files
committed
Updated changelog, version, and copyright notices. Removed trailing whitespace from the class file.
1 parent 5eb7480 commit 3ef0454

File tree

3 files changed

+69
-66
lines changed

3 files changed

+69
-66
lines changed

changelog

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@
44
Added requirements checks.
55
1.0.2 - 2013-01-07
66
Added bug fix that caused source images with transparency to have artifacts when output at the same dimensions as the source.
7+
1.0.3 - 2016-07-22
8+
Updated class constructor to __construct() as PHP4-style constructors are now deprecated. Props @nuxodin.
9+
Removed trailing whitespace from blank lines.

class-php-ico.php

Lines changed: 65 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<?php
22

33
/*
4-
Copyright 2011-2013 Chris Jean & iThemes
4+
Copyright 2011-2016 Chris Jean & iThemes
55
Licensed under GPLv2 or above
66
7-
Version 1.0.2
7+
Version 1.0.3
88
*/
99

1010
class PHP_ICO {
@@ -15,16 +15,16 @@ class PHP_ICO {
1515
* @access private
1616
*/
1717
var $_images = array();
18-
18+
1919
/**
2020
* Flag to tell if the required functions exist.
2121
*
2222
* @var boolean
2323
* @access private
2424
*/
2525
var $_has_requirements = false;
26-
27-
26+
27+
2828
/**
2929
* Constructor - Create a new ICO generator.
3030
*
@@ -47,21 +47,21 @@ function __construct( $file = false, $sizes = array() ) {
4747
'imagesy',
4848
'imagecopyresampled',
4949
);
50-
50+
5151
foreach ( $required_functions as $function ) {
5252
if ( ! function_exists( $function ) ) {
5353
trigger_error( "The PHP_ICO class was unable to find the $function function, which is part of the GD library. Ensure that the system has the GD library installed and that PHP has access to it through a PHP interface, such as PHP's GD module. Since this function was not found, the library will be unable to create ICO files." );
5454
return;
5555
}
5656
}
57-
57+
5858
$this->_has_requirements = true;
59-
60-
59+
60+
6161
if ( false != $file )
6262
$this->add_image( $file, $sizes );
6363
}
64-
64+
6565
/**
6666
* Add an image to the generator.
6767
*
@@ -77,39 +77,39 @@ function __construct( $file = false, $sizes = array() ) {
7777
function add_image( $file, $sizes = array() ) {
7878
if ( ! $this->_has_requirements )
7979
return false;
80-
80+
8181
if ( false === ( $im = $this->_load_image_file( $file ) ) )
8282
return false;
83-
84-
83+
84+
8585
if ( empty( $sizes ) )
8686
$sizes = array( imagesx( $im ), imagesy( $im ) );
87-
87+
8888
// If just a single size was passed, put it in array.
8989
if ( ! is_array( $sizes[0] ) )
9090
$sizes = array( $sizes );
91-
91+
9292
foreach ( (array) $sizes as $size ) {
9393
list( $width, $height ) = $size;
94-
94+
9595
$new_im = imagecreatetruecolor( $width, $height );
96-
96+
9797
imagecolortransparent( $new_im, imagecolorallocatealpha( $new_im, 0, 0, 0, 127 ) );
9898
imagealphablending( $new_im, false );
9999
imagesavealpha( $new_im, true );
100-
100+
101101
$source_width = imagesx( $im );
102102
$source_height = imagesy( $im );
103-
103+
104104
if ( false === imagecopyresampled( $new_im, $im, 0, 0, 0, 0, $width, $height, $source_width, $source_height ) )
105105
continue;
106-
106+
107107
$this->_add_image_data( $new_im );
108108
}
109-
109+
110110
return true;
111111
}
112-
112+
113113
/**
114114
* Write the ICO file data to a file path.
115115
*
@@ -119,23 +119,23 @@ function add_image( $file, $sizes = array() ) {
119119
function save_ico( $file ) {
120120
if ( ! $this->_has_requirements )
121121
return false;
122-
122+
123123
if ( false === ( $data = $this->_get_ico_data() ) )
124124
return false;
125-
125+
126126
if ( false === ( $fh = fopen( $file, 'w' ) ) )
127127
return false;
128-
128+
129129
if ( false === ( fwrite( $fh, $data ) ) ) {
130130
fclose( $fh );
131131
return false;
132132
}
133-
133+
134134
fclose( $fh );
135-
135+
136136
return true;
137137
}
138-
138+
139139
/**
140140
* Generate the final ICO data by creating a file header and adding the image data.
141141
*
@@ -144,29 +144,29 @@ function save_ico( $file ) {
144144
function _get_ico_data() {
145145
if ( ! is_array( $this->_images ) || empty( $this->_images ) )
146146
return false;
147-
148-
147+
148+
149149
$data = pack( 'vvv', 0, 1, count( $this->_images ) );
150150
$pixel_data = '';
151-
151+
152152
$icon_dir_entry_size = 16;
153-
153+
154154
$offset = 6 + ( $icon_dir_entry_size * count( $this->_images ) );
155-
155+
156156
foreach ( $this->_images as $image ) {
157157
$data .= pack( 'CCCCvvVV', $image['width'], $image['height'], $image['color_palette_colors'], 0, 1, $image['bits_per_pixel'], $image['size'], $offset );
158158
$pixel_data .= $image['data'];
159-
159+
160160
$offset += $image['size'];
161161
}
162-
162+
163163
$data .= $pixel_data;
164164
unset( $pixel_data );
165-
166-
165+
166+
167167
return $data;
168168
}
169-
169+
170170
/**
171171
* Take a GD image resource and change it into a raw BMP format.
172172
*
@@ -175,59 +175,59 @@ function _get_ico_data() {
175175
function _add_image_data( $im ) {
176176
$width = imagesx( $im );
177177
$height = imagesy( $im );
178-
179-
178+
179+
180180
$pixel_data = array();
181-
181+
182182
$opacity_data = array();
183183
$current_opacity_val = 0;
184-
184+
185185
for ( $y = $height - 1; $y >= 0; $y-- ) {
186186
for ( $x = 0; $x < $width; $x++ ) {
187187
$color = imagecolorat( $im, $x, $y );
188-
188+
189189
$alpha = ( $color & 0x7F000000 ) >> 24;
190190
$alpha = ( 1 - ( $alpha / 127 ) ) * 255;
191-
191+
192192
$color &= 0xFFFFFF;
193193
$color |= 0xFF000000 & ( $alpha << 24 );
194-
194+
195195
$pixel_data[] = $color;
196-
197-
196+
197+
198198
$opacity = ( $alpha <= 127 ) ? 1 : 0;
199-
199+
200200
$current_opacity_val = ( $current_opacity_val << 1 ) | $opacity;
201-
201+
202202
if ( ( ( $x + 1 ) % 32 ) == 0 ) {
203203
$opacity_data[] = $current_opacity_val;
204204
$current_opacity_val = 0;
205205
}
206206
}
207-
207+
208208
if ( ( $x % 32 ) > 0 ) {
209209
while ( ( $x++ % 32 ) > 0 )
210210
$current_opacity_val = $current_opacity_val << 1;
211-
211+
212212
$opacity_data[] = $current_opacity_val;
213213
$current_opacity_val = 0;
214214
}
215215
}
216-
216+
217217
$image_header_size = 40;
218218
$color_mask_size = $width * $height * 4;
219219
$opacity_mask_size = ( ceil( $width / 32 ) * 4 ) * $height;
220-
221-
220+
221+
222222
$data = pack( 'VVVvvVVVVVV', 40, $width, ( $height * 2 ), 1, 32, 0, 0, 0, 0, 0, 0 );
223-
223+
224224
foreach ( $pixel_data as $color )
225225
$data .= pack( 'V', $color );
226-
226+
227227
foreach ( $opacity_data as $opacity )
228228
$data .= pack( 'N', $opacity );
229-
230-
229+
230+
231231
$image = array(
232232
'width' => $width,
233233
'height' => $height,
@@ -236,10 +236,10 @@ function _add_image_data( $im ) {
236236
'size' => $image_header_size + $color_mask_size + $opacity_mask_size,
237237
'data' => $data,
238238
);
239-
239+
240240
$this->_images[] = $image;
241241
}
242-
242+
243243
/**
244244
* Read in the source image file and convert it into a GD image resource.
245245
*
@@ -249,16 +249,16 @@ function _load_image_file( $file ) {
249249
// Run a cheap check to verify that it is an image file.
250250
if ( false === ( $size = getimagesize( $file ) ) )
251251
return false;
252-
252+
253253
if ( false === ( $file_data = file_get_contents( $file ) ) )
254254
return false;
255-
255+
256256
if ( false === ( $im = imagecreatefromstring( $file_data ) ) )
257257
return false;
258-
258+
259259
unset( $file_data );
260-
261-
260+
261+
262262
return $im;
263263
}
264264
}

license.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
PHP ICO - The PHP ICO Generator
22

3-
Copyright 2011-2013 Chris Jean
3+
Copyright 2011-2016 Chris Jean
44

55
PHP ICO is free software; you can redistribute it and/or modify
66
it under the terms of the GNU General Public License as published by

0 commit comments

Comments
 (0)