Skip to content

Commit 8ad8d87

Browse files
committed
v1.0.0
1 parent bde6c42 commit 8ad8d87

File tree

4 files changed

+63
-52
lines changed

4 files changed

+63
-52
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# phpBB Image upload use ImageMagick
22

33
## Description
4-
This extension us the PHP imagick class to modify upload image for improved quality.
5-
It can change the image size and/or the image file size. Rotate thumbnails according to their exif information. Remove EXIF data.
4+
This extension us the PHP Imagick class to modify upload image for improved quality.
5+
This extension can change the image size and/or the image file size. It rotate images and thumbnails according to their EXIF information and it can remove the EXIF data.
66

77
#### Settings in User Control Panel
88
- No settings.
@@ -31,11 +31,11 @@ For full functionality "Maximum image dimensions" in "ACP" > "Posting" > "Attach
3131
- Click the `Disable` link for "Image upload use ImageMagick".
3232
- Delete the `imgupload` folder from `phpBB3/ext/imcger/`.
3333
- Copy the extension to `phpBB3/ext/imcger/imgupload`.
34-
- Go to "ACP" > "Customise" > "Manage extensions" and enable the "Collapse Quote" extension.
34+
- Go to "ACP" > "Customise" > "Manage extensions" and enable the "Image upload use ImageMagick" extension.
3535

3636
## Changelog
3737

38-
### v1.0.0 (09-07-2022)
38+
### v1.0.0 (21-07-2022)
3939
- Version check
4040
- Check system requirement
4141
- Controller for ACP template

imcger/imgupload/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Description
44
This extension us the PHP imagick class to modify upload image for improved quality.
5-
It can change the image size and/or the image file size. Rotate thumbnails according to their exif information. Remove EXIF data.
5+
This extension can change the image size and/or the image file size. It rotate images and thumbnails according to their EXIF information and it can remove the EXIF data.
66

77
#### Settings in User Control Panel
88
- No settings.
@@ -31,11 +31,11 @@ For full functionality "Maximum image dimensions" in "ACP" > "Posting" > "Attach
3131
- Click the `Disable` link for "Image upload use ImageMagick".
3232
- Delete the `imgupload` folder from `phpBB3/ext/imcger/`.
3333
- Copy the extension to `phpBB3/ext/imcger/imgupload`.
34-
- Go to "ACP" > "Customise" > "Manage extensions" and enable the "Collapse Quote" extension.
34+
- Go to "ACP" > "Customise" > "Manage extensions" and enable the "Image upload use ImageMagick" extension.
3535

3636
## Changelog
3737

38-
### v1.0.0 (09-07-2022)
38+
### v1.0.0 (21-07-2022)
3939
- Version check
4040
- Check system requirement
4141
- Controller for ACP template

imcger/imgupload/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "Using ImageMagick php librarie for resize image attachments and creating thumbnails.",
55
"homepage": "https://github.com/IMC-GER/phpBB-Image-upload-use-ImageMagick/tags",
66
"version": "1.0.0",
7-
"time": "2022-07-09",
7+
"time": "2022-07-21",
88
"license": "GPL-2.0-only",
99
"authors": [{
1010
"name": "Thorsten Ahlers",

imcger/imgupload/event/main_listener.php

Lines changed: 55 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
* An extension for the phpBB Forum Software package.
66
*
77
* @copyright (c) 2022, Thorsten Ahlers
8-
* @copyright (c) 2019, ftc2, Auto-Resize Images Server-side
98
* @copyright (c) 2018, canonknipser, ImageMagick Thumbnailer, http://canonknipser.com
109
* @license GNU General Public License, version 2 (GPL-2.0)
1110
*
@@ -78,25 +77,22 @@ public function imcger_create_tumbnail($event)
7877
}
7978

8079
/* resize the Image */
81-
$thumbnail->resizeImage($new_width, $new_height, \Imagick::FILTER_LANCZOS, 1, false);
80+
$thumbnail->resizeImage($new_width, $new_height, \Imagick::FILTER_LANCZOS, 1);
8281

8382
/* Set image format */
84-
$this->set_image_format($thumbnail, $event['mimetype']);
83+
$image_format = $this->set_image_format($thumbnail, $event['mimetype']);
8584

8685
/* Compression quality is read from config, set in ACP */
8786
$this->set_image_compression($thumbnail, $this->config['imcger_imgupload_tum_quality']);
8887

8988
/* Strip EXIF data and image profile */
90-
if ($this->config['imcger_imgupload_del_exif'])
89+
if ($this->config['imcger_imgupload_del_exif'] && $image_format == 'JPEG')
9190
{
9291
$thumbnail->stripImage();
9392
}
9493

9594
/* Store the image */
96-
if ($thumbnail->writeImage($event['destination']))
97-
{
98-
$thumbnail_created = true;
99-
}
95+
$thumbnail_created = $thumbnail->writeImage($event['destination']);
10096

10197
/* set return value */
10298
$event['thumbnail_created'] = $thumbnail_created;
@@ -112,8 +108,6 @@ public function imcger_modify_uploaded_file($event)
112108
if ($event['is_image'])
113109
{
114110
$write_image = false; // set to true wenn image attribute changed
115-
$image_max_width = $this->config['imcger_imgupload_max_width'];
116-
$image_max_height = $this->config['imcger_imgupload_max_height'];
117111
$image_quality = $this->config['imcger_imgupload_img_quality'];
118112
$image_del_exif = $this->config['img_strip_metadata'];
119113
$image_max_filesize = $this->config['imcger_imgupload_max_filesize'];
@@ -127,36 +121,8 @@ public function imcger_modify_uploaded_file($event)
127121
/* rotate the image according it's orientation flag */
128122
$img = $this->image_auto_rotate($image);
129123

130-
/* get image dimensions */
131-
$width = $image->getImageWidth();
132-
$height = $image->getImageHeight();
133-
134-
/* image side ratio */
135-
$side_ratio = $width / $height;
136-
137-
/* set new images width */
138-
if ($image_max_width && $image_max_width < $width)
139-
{
140-
$width = $image_max_width;
141-
$height = (int) ($width / $side_ratio);
142-
143-
$write_image = true;
144-
}
145-
146-
/* set new images height */
147-
if ($image_max_height && $image_max_height < $height)
148-
{
149-
$height = $image_max_height;
150-
$width = (int) ($height * $side_ratio);
151-
152-
$write_image = true;
153-
}
154-
155-
/* when changed dimensions resize the Image */
156-
if ($write_image)
157-
{
158-
$image->resizeImage($width, $height, \Imagick::FILTER_LANCZOS, 1, false);
159-
}
124+
/* resize the image */
125+
$write_image = $this->resize_image($image);
160126

161127
/* set image format */
162128
$image_format = $this->set_image_format($image, $event['filedata']['mimetype']);
@@ -204,6 +170,53 @@ public function imcger_modify_uploaded_file($event)
204170
}
205171
}
206172

173+
/**
174+
* resize image if image to large
175+
*
176+
* @param object $image image object
177+
*
178+
* @return bool $img_resize images is resize
179+
*/
180+
function resize_image($image)
181+
{
182+
$image_max_width = $this->config['imcger_imgupload_max_width'];
183+
$image_max_height = $this->config['imcger_imgupload_max_height'];
184+
$img_resize = false;
185+
186+
/* get image dimensions */
187+
$width = $image->getImageWidth();
188+
$height = $image->getImageHeight();
189+
190+
/* image side ratio */
191+
$side_ratio = $width / $height;
192+
193+
/* set new images width */
194+
if ($image_max_width && $image_max_width < $width)
195+
{
196+
$width = $image_max_width;
197+
$height = (int) ($width / $side_ratio);
198+
199+
$img_resize = true;
200+
}
201+
202+
/* set new images height */
203+
if ($image_max_height && $image_max_height < $height)
204+
{
205+
$height = $image_max_height;
206+
$width = (int) ($height * $side_ratio);
207+
208+
$img_resize = true;
209+
}
210+
211+
/* when changed dimensions resize the Image */
212+
if ($img_resize)
213+
{
214+
$image->resizeImage($width, $height, \Imagick::FILTER_LANCZOS, 1, false);
215+
}
216+
217+
return $img_resize;
218+
}
219+
207220
/**
208221
* set the image format for the generated image
209222
*
@@ -315,17 +328,15 @@ function image_auto_rotate($image)
315328
$image->flipImage();
316329
break;
317330
case \Imagick::ORIENTATION_LEFTTOP:
318-
$image->flipImage();
319-
$image->rotateImage("#000", 90);
331+
$image->transposeImage();
320332
$is_rotate = true;
321333
break;
322334
case \Imagick::ORIENTATION_RIGHTTOP:
323335
$image->rotateImage("#000", 90);
324336
$is_rotate = true;
325337
break;
326338
case \Imagick::ORIENTATION_RIGHTBOTTOM:
327-
$image->flopImage();
328-
$image->rotateImage("#000", 90);
339+
$image->transverseImage();
329340
$is_rotate = true;
330341
break;
331342
case \Imagick::ORIENTATION_LEFTBOTTOM:

0 commit comments

Comments
 (0)