2

That title might be a little confusing (sorry) but I'm using Channel Images to run some galleries; the client is giving me jpegs that were saved at highest quality, so they are too large (about 1-1.5MB each). CI can compress all the images at a specified rate, but what I'm looking for instead is a variable compression rate, so that images will be saved at the highest quality that keeps them under 200kb (for example).

In other words, I want the images compressed to the point that they reach 200kb, and not more: highly saturated images would therefore be more compressed than simple images.

Any ideas on how to achieve this? I'm trying to make things a little simpler for one of my clients.

4 Answers 4

3

As I know, is no EE add-ons which can completely help you to get what you want.

Possible solution:

  1. Upload file using any of exist EE add-ons, make manipulation with exist option (width, height, crop etc.)

  2. Then setup on the server CRON job with batch which will run couple times per day and check if new files in upload folder exist. For new files needs to run jpegoptim with key --size

-S, --size=< size >

Try to optimize file to given size (disables lossless opti- mizaiont mode). Target size is specified either in kilobytes (1 - n) or as percentage (1% - 99%) of the original file size.

example of optimization script for this:

#!/bin/sh
declare -a iPath=('/home/user/site.com/public_html/images/upload');
lof_file=('/tmp/otimazer.log')

start_time=$(date +%s)

if [ -f $lof_file ];
then
    dt_mod=("-newer $lof_file")
else
    dt_mod=""
fi

for i in "${iPath[@]}"
do
    find $i  -iname "*.j*g" $dt_mod -type f | xargs jpegoptim --strip-all --size=200
done

end_time=$(date +%s)

duration=$(($end_time-$start_time))

echo "$(date +%Y-%m-%d-%H-%M-%S) : duration = $duration" >> $lof_file

p.s. For my clients servers I usually setup IMGO.

1
  • Thanks for the interesting idea! Probably I will just have the client prepare the images to a good file size in this case; what you recommend is a little beyond me!
    – edward
    Nov 21, 2013 at 14:59
0

Try enforcing an upload limit and the different image manipulation settings on your upload directory.

Adjusting the output settings on the fly would be difficult to pull off. If you require more advanced manipulation, take a look at CE Image from CausingEffect.

0

While not allowing you set a max file size CE Image will let you set an image quality percentage - see the docs here. Otherwise I think Max's answer is best ATM.

0

Use the "maxb" parameter of phpThumb: http://phpthumb.sourceforge.net

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.