[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Resizing pictures for file size

Pupeno

2/3/2008 10:26:00 PM

Hello,

I'm using rmagick but I'm open to other libraries if needed. I want to
resize an image, scale actually (mantaining the aspect ratio) so that
the
size of the file is lower than a certain amount of bytes. Any ideas
how to
do this?

Thanks.
--
J. Pablo Fernández <pupeno@pupeno.com> (http://...)
5 Answers

Tim Hunter

2/3/2008 11:34:00 PM

0

J. Pablo Fernández wrote:
> Hello,
>
> I'm using rmagick but I'm open to other libraries if needed. I want to
> resize an image, scale actually (mantaining the aspect ratio) so that
> the
> size of the file is lower than a certain amount of bytes. Any ideas
> how to
> do this?
>
> Thanks.
> --
> J. Pablo Fernández <pupeno@pupeno.com> (http://...)
>

I can't speak for other libraries, but this is not possible with
RMagick. This question comes up from time-to-time on the ImageMagick
forum but the answer is always "not possible" other than just by
trial-and-error.

--
RMagick: http://rmagick.ruby...
RMagick 2: http://rmagick.ruby...rmagick2.html

David Moreno

2/4/2008 1:17:00 AM

0

On Mon, 2008-02-04 at 08:34 +0900, Tim Hunter wrote:
> J. Pablo Fern=E1ndez wrote:
> > Hello,
> >=20
> > I'm using rmagick but I'm open to other libraries if needed. I want to
> > resize an image, scale actually (mantaining the aspect ratio) so that
> > the
> > size of the file is lower than a certain amount of bytes. Any ideas
> > how to
> > do this?
> >=20
> > Thanks.
> > --
> > J. Pablo Fern=E1ndez <pupeno@pupeno.com> (http://...)
> >=20
>=20
> I can't speak for other libraries, but this is not possible with=20
> RMagick. This question comes up from time-to-time on the ImageMagick=20
> forum but the answer is always "not possible" other than just by=20
> trial-and-error.

What exactly is not possible? Resize according to the certain amount of
bytes after the resize?

--=20
David.
First time I had read the Bible/ It had stroke me as unwitty!



Tim Hunter

2/4/2008 1:30:00 AM

0

David Moreno wrote:
> On Mon, 2008-02-04 at 08:34 +0900, Tim Hunter wrote:
>> J. Pablo Fernández wrote:
>>> Hello,
>>>
>>> I'm using rmagick but I'm open to other libraries if needed. I want to
>>> resize an image, scale actually (mantaining the aspect ratio) so that
>>> the
>>> size of the file is lower than a certain amount of bytes. Any ideas
>>> how to
>>> do this?
>>>
>>> Thanks.
>>> --
>>> J. Pablo Fernández <pupeno@pupeno.com> (http://...)
>>>
>> I can't speak for other libraries, but this is not possible with
>> RMagick. This question comes up from time-to-time on the ImageMagick
>> forum but the answer is always "not possible" other than just by
>> trial-and-error.
>
> What exactly is not possible? Resize according to the certain amount of
> bytes after the resize?
>

There is no method in RMagick that takes an image and a file size in
bytes and returns an image that, when saved to a file, produces a file
close to or no larger than the specified size. The file size depends on
the image format, the compression level, and the image itself.

--
RMagick: http://rmagick.ruby...
RMagick 2: http://rmagick.ruby...rmagick2.html

Marcin Raczkowski

2/4/2008 2:03:00 AM

0

> There is no method in RMagick that takes an image and a file size in
> bytes and returns an image that, when saved to a file, produces a file
> close to or no larger than the specified size. The file size depends on
> the image format, the compression level, and the image itself.

There are tools that can estaminate size of file after compresion - but
they'll never give you exact size without actual compression.

So .. you take script, 20-30 simple images, take each one, start with
some quality - and incrementally decrase untill size fits, then you take
mean and min from qualities.

now you have 2 qualities - one that 50% of images should fit with size -
and second that almost all should fit.

that's assuming that your surce images have simillar resolutions.

greets

Tim Hunter

2/4/2008 2:09:00 AM

0

Marcin Raczkowski wrote:
>> There is no method in RMagick that takes an image and a file size in
>> bytes and returns an image that, when saved to a file, produces a file
>> close to or no larger than the specified size. The file size depends
>> on the image format, the compression level, and the image itself.
>
> There are tools that can estaminate size of file after compresion - but
> they'll never give you exact size without actual compression.
>
> So .. you take script, 20-30 simple images, take each one, start with
> some quality - and incrementally decrase untill size fits, then you take
> mean and min from qualities.
>
> now you have 2 qualities - one that 50% of images should fit with size -
> and second that almost all should fit.
>
> that's assuming that your surce images have simillar resolutions.
>
> greets
>

Sounds like a plan. Maybe the OP will adopt it if he can't find a
library that will do what he wants automatically.

--
RMagick: http://rmagick.ruby...
RMagick 2: http://rmagick.ruby...rmagick2.html