|
11 | 11 | * @email matthew@dps.uk.com
|
12 | 12 | *
|
13 | 13 | * @file image_moo.php
|
14 |
| - * @version 1.1.6 |
15 |
| - * @date 2014 Feb 5 |
| 14 | + * @version 1.1.7 |
| 15 | + * @date 2022 Jun 21 |
16 | 16 | *
|
17 | 17 | * Copyright (c) 2011-2014 Matthew (Mat-Moo.com) Augier
|
18 |
| - * |
19 |
| - * Requires PHP 5 and GD2! |
| 18 | + * |
| 19 | + * Requires PHP 5+ and GD2! |
20 | 20 | *
|
21 | 21 | * Example usage
|
22 | 22 | * $this->image_moo->load("file")->resize(64,40)->save("thumb")->resize(640,480)->save("medium");
|
|
27 | 27 | *
|
28 | 28 | * image manipulation functions
|
29 | 29 | * -----------------------------------------------------------------------------
|
30 |
| - * load($x) - Loads an image file specified by $x - JPG, PNG, GIF supported |
| 30 | + * load($x) - Loads an image file specified by $x - JPG, PNG, GIF, WEBP supported |
31 | 31 | * load_temp() - Takes a cropped/altered image and makes it the main image to work with.
|
32 |
| - * save($x) - Saved the manipulated image (if applicable) to file $x - JPG, PNG, GIF supported |
| 32 | + * save($x) - Saved the manipulated image (if applicable) to file $x - JPG, PNG, GIF, WEBP supported |
33 | 33 | * get_data_stream($filename="") - Return the image as a stream so that it can be sent as source data to the output
|
34 | 34 | * save_pa($prepend="", $append="", $overwrite=FALSE) - Saves using the original image name but with prepend and append text, e.g. load('moo.jpg')->save_pa('pre_','_app') would save as filename pre_moo_app.jpg
|
35 |
| - * save_dynamic($filename="") - Saves as a stream output, use filename to return png/jpg/gif etc., default is jpeg |
36 |
| - * resize($x,$y=FALSE,$pad=FALSE) - Proportioanlly resize original image using the bounds $x and $y (if y is false x size is used), if padding is set return image is as defined centralised using BG colour |
37 |
| - * resize_crop($x,$y) - Proportioanlly resize original image using the bounds $x and $y but cropped to fill dimensions |
| 35 | + * save_dynamic($filename="") - Saves as a stream output, use filename to return png/jpg/gif/webp etc., default is jpeg |
| 36 | + * resize($x,$y=FALSE,$pad=FALSE) - Proportionally resize original image using the bounds $x and $y (if y is false x size is used), if padding is set return image is as defined centralised using BG colour |
| 37 | + * resize_crop($x,$y) - Proportionally resize original image using the bounds $x and $y but cropped to fill dimensions |
38 | 38 | * stretch($x,$y) - Take the original image and stretch it to fill new dimensions $x $y
|
39 | 39 | * crop($x1,$y1,$x2,$y2) - Crop the original image using Top left, $x1,$y1 to bottom right $x2,y2. New image size =$x2-x1 x $y2-y1
|
40 | 40 | * rotate($angle) - Rotates the work image by X degrees, normally 90,180,270 can be any angle.Excess filled with background colour
|
|
52 | 52 | * allow_scale_up($onoff = FALSE) - When using resize, setting this to tru will allow small images to increase in size, otherwise they do not get resized
|
53 | 53 | * real_filesize() - returns the filesize of the image in bytes etc.
|
54 | 54 | * display_errors($open = '<p>', $close = '</p>') - Display errors as Ci standard style
|
55 |
| - * set_jpeg_quality($x) - quality to wrte jpeg files in for save, default 75 (1-100) |
| 55 | + * set_jpeg_quality($x) - quality to write jpeg/webp files in for save, default 75 (1-100) |
56 | 56 | * set_watermark_transparency($x) - the opacity of the watermark 1-100, 1-just about see, 100=solid
|
57 | 57 | * check_gd() - Run to see if you server can use this library
|
58 | 58 | * clear_temp() - Call to clear the temp changes using the master image again
|
|
70 | 70 | * Cole spotting the resize flaw and providing a fix
|
71 | 71 | * Nuno Mira for suggesting the new width/new size on teh ci forums
|
72 | 72 | * HugoSolar for transparent rotate
|
| 73 | + * EbbenF/Locally.com for webp support |
73 | 74 | *
|
74 | 75 | */
|
75 | 76 |
|
@@ -106,7 +107,7 @@ function __construct()
|
106 | 107 | // create stuff here as needed
|
107 | 108 | //----------------------------------------------------------------------------------------------------------
|
108 | 109 | {
|
109 |
| - log_message('debug', "Image Moo Class Initialized"); |
| 110 | + // log_message('debug', "Image Moo Class Initialized"); |
110 | 111 | if ($this->jpeg_ignore_warnings) $this->ignore_jpeg_warnings();
|
111 | 112 | if ($this->can_stretch) $this->can_stretch(TRUE);
|
112 | 113 | }
|
@@ -259,6 +260,9 @@ function get_data_stream($filename="")
|
259 | 260 | case "PNG" :
|
260 | 261 | imagepng($this->temp_image);
|
261 | 262 | break;
|
| 263 | + case "WEBP": |
| 264 | + imagewebp($this->temp_image); |
| 265 | + break; |
262 | 266 | default:
|
263 | 267 | $this->set_error('Extension not recognised! Must be jpg/png/gif');
|
264 | 268 | return FALSE;
|
@@ -311,6 +315,11 @@ function save_dynamic($filename="")
|
311 | 315 | imagepng($this->temp_image);
|
312 | 316 | return $this;
|
313 | 317 | break;
|
| 318 | + case "WEBP": |
| 319 | + header("Content-type: image/webp"); |
| 320 | + imagewebp($this->temp_image, NULL, $this->jpeg_quality); |
| 321 | + return $this; |
| 322 | + break; |
314 | 323 | }
|
315 | 324 | $this->set_error('Unable to save, extension not GIF/JPEG/JPG/PNG');
|
316 | 325 | return $this;
|
@@ -374,6 +383,10 @@ function save($filename,$overwrite=FALSE)
|
374 | 383 | imagepng($this->temp_image, $filename);
|
375 | 384 | return $this;
|
376 | 385 | break;
|
| 386 | + case "WEBP" : |
| 387 | + imagewebp($this->temp_image, $filename, $this->jpeg_quality); |
| 388 | + return $this; |
| 389 | + break; |
377 | 390 | }
|
378 | 391 |
|
379 | 392 | // invalid filetype?!
|
@@ -410,6 +423,9 @@ private function _load_image($filename)
|
410 | 423 | case "image/png" :
|
411 | 424 | return @imagecreatefrompng($filename);
|
412 | 425 | break;
|
| 426 | + case "image/webp" : |
| 427 | + return @imagecreatefromwebp($filename); |
| 428 | + break; |
413 | 429 | }
|
414 | 430 | }
|
415 | 431 | catch (Exception $e)
|
|
0 commit comments