/usr/share/php/Imlib/class.ImlibImage.php is in php-imlib 0.7-4.1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 | <?php
/**
* Handles image loading and saving, parameters, manipulation, and rendering.
*
* This class contains methods for the loading and saving of image files. Also
* contained in this class are functions for getting and setting image parameters,
* image modification, and rendering.
*
* @version 0.3
* @author Matt McClanahan <cardinal@dodds.net>
* @package Imlib
* @access public
*/
class ImlibImage
{
/**
* The image resource id#
*
* @var integer $id
* @see create(), get_id()
* @access private
*/
var $id;
/**
* ImlibImage constructor
*
* @access public
*/
function ImlibImage() { $this->id = 0; }
/**
* Callback for functions which query the current instance's attributes
*
* @param string The name of the function to call
* @return mixed String or int
* @access private
*/
function _get_cb($cb)
{
if (!is_resource($this->id))
return false;
$cbname = 'imlib_image_' . $cb;
return $cbname($this->id);
}
/**
* Callback for functions which flip or tile the current instance
*
* @param string The name of the function to call
* @access private
*/
function _no_param_cb($cb)
{
if (!is_resource($this->id))
return false;
$cbname = 'imlib_image_' . $cb;
return $cbname($this->id);
}
/**
* Blend a region of the current image onto the region of another ImlibImage
*
* @param int Resource id# of the destination image
* @param bool Merge alpha
* @param int Upper left source X coordinate
* @param int Upper left source Y coordinate
* @param int Source width
* @param int Source height
* @param int Upper left destination X coordinate
* @param int Upper left destination Y coordinate
* @param int Destination width
* @param int Destination height
* @param bool Dither
* @param bool Blend
* @param bool Alias
* @access public
*/
function blend_onto_image($dst,$alpha,$sx,$sy,$sw,$sh,$dx,$dy,$dw,$dh,
$dither,$blend,$alias)
{
if (!is_resource($this->id) || !is_resource($dst))
return false;
imlib_blend_image_onto_image($dst,$this->id,$alpha,$sx,$sy,$sw,$sh,
$dx,$dy,$dw,$dh,$dither,$blend,$alias);
}
/**
* Blur an image with a given blur radius
*
* @param int Blur radius
* @access public
*/
function blur($r)
{
imlib_image_blur($this->id,$r);
}
/**
* Create a clone of the current instance, return a new ImlibImage
*
* @return object ImlibImage
* @access public
*/
function create_clone()
{
if (!is_resource($this->id))
return false;
$clone = new ImlibImage();
$clone->id = imlib_clone_image($this->id);
return $clone;
}
/**
* Create a cropped ImlibImage from a region of the current instance, return a new ImlibImage
*
* @param int Upper left X coordinate to crop from
* @param int Upper left Y coordinate to crop from
* @param int Width to crop
* @param int Height to crop
* @return object ImlibImage
* @access public
*/
function create_cropped($sx,$sy,$sw,$sh)
{
if (!is_resource($this->id))
return false;
$crop = new ImlibImage();
$crop->id = imlib_create_cropped_image($this->id,$sx,$sy,$sw,$sh);
return $crop;
}
/**
* Create a cropped, scaled ImlibImage from a region of the current instance, return a new ImlibImage
*
* @param int Upper left X coordinate to crop from
* @param int Upper left Y coordinate to crop from
* @param int Width to crop
* @param int Height to crop
* @param int Width to scale the cropped region to
* @param int Height to scale the cropped region to
* @return object ImlibImage
* @access public
*/
function create_cropped_scaled($sx,$sy,$sw,$sh,$dw,$dh)
{
if (!is_resource($this->id))
return false;
$thumb = new ImlibImage();
$thumb->id = imlib_create_cropped_scaled_image($this->id,
$sx,$sy,$sw,$sh, $dw,$dh);
return $thumb;
}
/**
* Create an image resource to use with this instance
*
* @param int Width of the image
* @param int Height of the image
* @return int Resource id# that was created
* @access public
* @see get_id(), $id
*/
function create($width,$height)
{
if (is_resource($this->id))
return false;
return $this->id = imlib_create_image($width,$height);
}
/**
* Create a rotated ImlibImage, return a new ImlibImage
*
* If radians is specified, degrees will be ignored.
*
* @param float Angle to rotate the image
* @param float Radians to rotate the image
* @return object ImlibImage
* @access public
*/
function create_rotated($degrees,$radians=0.0)
{
if (!is_resource($this->id))
return false;
if ($radians)
$num = $radians;
else
$num = $degrees;
$rotated = new ImlibImage();
$rotated->id = imlib_create_rotated_image($this->id,$num);
return $rotated;
}
/**
* Create a scaled ImlibImage, return a new ImlibImage
*
* If $height is not specified, it will be calculated from the dimensions
* of the current image, so that the aspect ratio is preserved.
*
* @param integer Width to scale the new image to
* @param integer Height to scale the new image to (Optional)
* @return object ImlibImage
* @access public
*/
function create_scaled($width,$height=0)
{
if (!is_resource($this->id))
return false;
$scaled = new ImlibImage();
$scaled->id = imlib_create_scaled_image($this->id,$width,$height);
return $scaled;
}
/**
* Output the raw image data of the current instance to stdout
*
* @param integer Quality or compression level to use
* @access public
*/
function dump($quality=75)
{
if (!is_resource($this->id))
return false;
if (!imlib_dump_image($this->id,$err,$quality))
return false;
else
return true;
}
/**
* Flip the current image diagonally
*
* @access public
*/
function flip_diagonal() { return $this->_no_param_cb('flip_diagonal'); }
/**
* Flip the current image horizontally
*
* @access public
*/
function flip_horizontal() { return $this->_no_param_cb('flip_horizontal'); }
/**
* Flip the current image vertically
*
* @access public
*/
function flip_vertical() { return $this->_no_param_cb('flip_vertical'); }
/**
* Free the current instance and image resource
*
* @access public
*/
function free()
{
if (!is_resource($this->id))
return false;
imlib_free_image($this->id);
$this->id = 0;
}
/**
* Get the current filename, if it's set
*
* @return mixed Filename string or false.
* @access public
*/
function get_filename() { return $this->_get_cb('get_filename'); }
/**
* Get the current image format. The default is png.
*
* @return string Image format
* @access public
*/
function get_format() { return $this->_get_cb('format'); }
/**
* Get the current image's height
*
* @return integer Image height
* @access public
*/
function get_height() { return $this->_get_cb('get_height'); }
/**
* Get the current image's resource id#
*
* @return integer Current resource id#
* @access public
* @see $id, create()
*/
function get_id() { return $this->id; }
/**
* Get the current image's width
*
* @return integer Image width
* @access public
*/
function get_width() { return $this->_get_cb('get_width'); }
/**
* Check if the image has an alpha channel
*
* @return boolean
* @access public
*/
function has_alpha()
{
if (!is_resource($this->id))
return false;
return imlib_image_has_alpha($this->id);
}
/**
* Set the alpha channel of an image
*
* @param int The alpha level to set for the image
* @access public
*/
function modify_alpha($alpha)
{
if (!is_resource($this->id))
return false;
imlib_image_modify_alpha($this->id,$alpha);
}
/**
* Load an image file into the current instance
*
* @param string Filename
* @param integer Load error number. 0 for no error.
* @return integer Resource id# or false if load failed
* @access public
*/
function load($infile,$err=0)
{
if (is_resource($this->id))
return false;
$this->id = imlib_load_image_with_error_return($infile,&$err);
if (!is_resource($this->id) || $err)
return false;
else
return true;
}
/**
* Save the current instance to a file
*
* @param string Filename
* @param integer Quality or compression level to use
* @return bool False if the save failed
* @access public
*/
function save($outfile,$quality=75)
{
if (!is_resource($this->id))
return false;
if (!imlib_save_image($this->id,$outfile,&$err,$quality))
return false;
else
return true;
}
/**
* Set the image format for the current instance
*
* @param string File format
* @access public
*/
function set_format($format)
{
if (!is_resource($this->id))
return false;
return imlib_image_set_format($this->id,$format);
}
/**
* Sharpen an image with a given sharpen radius
*
* @param int Sharpen radius
* @access public
*/
function sharpen($r)
{
imlib_image_sharpen($this->id,$r);
}
/**
* Seamlessly tile the current image both horizontally and vertically
*
* @access public
*/
function tile() { return $this->_no_param_cb('tile'); }
/**
* Seamlessly tile the current image horizontally
*
* @access public
*/
function tile_horizontal() { return $this->_no_param_cb('tile_horizontal'); }
/**
* Seamlessly tile the current image vertically
*
* @access public
*/
function tile_vertical() { return $this->_no_param_cb('tile_vertical'); }
};
?>
|