Skip to main content
Topic: [ADDON] Resize attached images (Read 26899 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Re: [ADDON] Resize attached images

Reply #15

Grrrr ... namespace issue.  for ElkArte 1.1 ONLY, give this  Air_Resize.subs.php  (13.36 KB) a try. 

I'm note sure why you are not seeing the problem on your other 1.1 sites, since it should not work.  Maybe you don't have it enabled or have not triggered it due to the size limit or  ?  But really the existing mod should not work!

Re: [ADDON] Resize attached images

Reply #16

Most interesting.  The images get resized, for what that's worth.  If there's something strange, it's in the monkey cage. 

I'll try it tonight.  Thanks spuds!

Re: [ADDON] Resize attached images

Reply #17

That works!!  Thanks a million spuds.  You da man.  Sorry to be so troublesome. 

Re: [ADDON] Resize attached images

Reply #18

Good job. So now it's clearly not a new server fault after all. Though I however found it a little bit surprising when the same working forum only found error in the new server, this discussion is now out of topic. I hope there is a board where a discussion relating to a server can be made.

Re: [ADDON] Resize attached images

Reply #19

French translation in attachment.

Re: [ADDON] Resize attached images

Reply #20

I've updated the package http://addons.elkarte.net/utility/Attachment-Resize.html to version 1.0.2

It includes the above translation
Adds support for 1.1
Fixes a bug when allowing to convert from PNG to JPG, it was not updating the mime_type value in the DB

Re: [ADDON] Resize attached images

Reply #21

Quote from: Spuds – Fixes a bug when allowing to convert from PNG to JPG, it was not updating the mime_type value in the DB
this never worked for me, I just updated the addon and I upload a png file, but is not converted into jpg
sorry for my bad english

Re: [ADDON] Resize attached images

Reply #22

It would only convert it to JPG if it was required in order to obtain the file size limit.  So if its already a small enough file, then it should not change the encoding.

Re: [ADDON] Resize attached images

Reply #23

in the test I did, the original size of png image is 1,1 MB and once resized became 550 Kb (1200 px width) and the transparency disappeared, which makes me think is converted to jpg, but the file extension is still png. I thought it also change the file extension from png to jpg
Last Edit: March 08, 2017, 03:46:53 am by radu81
sorry for my bad english

Re: [ADDON] Resize attached images

Reply #24

It will
 
  • first do a WxH resize (if needed) keeping the same format,
  • check the file size, if at that point it is still to large in MB then
  • re-encode as a JPG (assuming its a PNG) and see if that fits inside the MB size limit.

No idea on the transparency or the encoding, there could still be a bugs ! ... Then again without the specific image and settings I'm kind of left choking my chicken :D
Last Edit: March 07, 2017, 09:39:51 pm by Spuds

Re: [ADDON] Resize attached images

Reply #25

I should stop making tests late night  :-[
I was wrong about the image, the trasparency is kept in png file, I was looking to a file edited by me  :-X . I attach here a zip containing the original, the resized file, and the settings I use.
sorry for my bad english

Re: [ADDON] Resize attached images

Reply #26

Cool .. I'll do some testing!

ETA:

Looking at your attachment settings, you have "Max size per attachment" set to 0, which means no limit.   This means there is no practical size limit imposed on an individual file.

The original PNG image was (1818 x 827) which is larger than the (1200 x 1200) limit you have set.  As such the file was proportionally resized to (1200 x 546) which saves some file size as expected (1Mb -> 541Kb)

At this point the program would check if 541Kb is at or under the individual size limit, and since you have no limit set, it passes that check and the program is done.

If however, and only for an example, you set a size limit of 400Kb, then the program would take that 541Kb oversize PNG and re-encode it as a JPG to see if it would then be <= 400Kb, and if so save it as that (a JPG). 

So again the Allow non-JPEG images to be reformatted to JPEG format when resizing."  setting will allow the system to reformat non-JPEG images into the JPEG format when necessary.  The system will try to maintain the existing format unless the resulting image is still in excess of the maximum file size allowed.  If it can keep a PNG as a PNG, it will do so (since its lossless)\

Now I'm going to actually test :D
Last Edit: March 08, 2017, 09:57:36 am by Spuds

Re: [ADDON] Resize attached images

Reply #27

Quote from: Spuds – At this point the program would check if 541Kb is at or under the individual size limit, and since you have no limit set, it passes that check and the program is done.

If however, and only for an example, you set a size limit of 400Kb, then the program would take that 541Kb oversize PNG and re-encode it as a JPG to see if it would then be <= 400Kb, and if so save it as that (a JPG). 
Now it's clear to me how it works, I misunderstood this part. I thought if I set a limit ( let's say 400 kb per image) I won't be able to upload an image bigger than 400 KB (original dimension). That's why I've set this field to 0.


Quote from: Spuds – So again the Allow non-JPEG images to be reformatted to JPEG format when resizing."  setting will allow the system to reformat non-JPEG images into the JPEG format when necessary.  The system will try to maintain the existing format unless the resulting image is still in excess of the maximum file size allowed.  If it can keep a PNG as a PNG, it will do so (since its lossless)\

Now I'm going to actually test :D
I just test it, and in fact it works as you described. I've set a 400kb limit per image and the PNG file is saved as jpg. I attach it here

Converting a png to jpg remove transparency, so the transparent part is now black. Is there a way to change this behaviour by changing transparent to white?

Re: [ADDON] Resize attached images

Reply #28

For Imagick only ....

in Graphics.subs.php
Code: (find) [Select]
			// Set jpeg image quality to 80
if ($default_formats[$preferred_format] === 'jpeg')
{
$imagick->setImageCompression(Imagick::COMPRESSION_JPEG);
$imagick->setImageCompressionQuality(80);
}
Code: (replace) [Select]
			// Set jpeg image quality to 80
if ($default_formats[$preferred_format] === 'jpeg')
{
$imagick->borderImage('white', 0, 0);
$imagick->setImageCompression(Imagick::COMPRESSION_JPEG);
$imagick->setImageCompressionQuality(80);
}

So just adding in that
$imagick->borderImage('white', 0, 0);
line should do the "trick"

Also note that 400 (or whatever size) you use is only enforced after the upload, as is the max size for all attachments.  The addon updates the attachment form to allow it to accept a file as large as your server setting will allow and the group of files to the max as well (post_max_size and file_max_size values or whatever they are).   This allows someone to upload their 5000 x 5000 x 6Mb cellphone pic and yet be resized (and possibly re-encoded) to fit to the ACP values.  Capisce  :)

Re: [ADDON] Resize attached images

Reply #29

There seems to be two mistakes in the english language files:

Code: [Select]
$txt['helpattachment_image_enabled_size'] = 'or large than %s KB.';

Missing "r" - should be "or larger..."

Code: [Select]
$txt['help_attachment_image_height'] = 'This allows you to set a maximum width for attachment images. Pictures smaller than the maximum will not be affected, larger images will be resized proportionately. This allows you to accept a larger image on upload and have it resized to save space. The maximum filesize parameter is still enforced.';

Should be "'This allows you to set a maximum height for attachment images." or not?

Below is the german translation.

Can it be there's a little bug with the help texts? When I click on one of those small "?" icons a window opens without text.  :o