This project has moved and is read-only. For the latest updates, please go here.

restrict the image file size created(or saved) in the hard disk

May 21, 2014 at 7:46 AM
Edited May 21, 2014 at 8:10 AM
I followed the documentation to convert other image file formats to a j2k image format with an extension j2k.
Here is my code(c#):
                   using (ImageMagick.MagickImage magickImage = new ImageMagick.MagickImage(datasetConversion.InFile))
                    {
                        magickImage.AddProfile(ColorProfile.SRGB);
                        magickImage.ColorSpace = ColorSpace.sRGB;
                        magickImage.CompressionMethod = CompressionMethod.JPEG2000;

                        magickImage.Write(datasetConversion.OutFile);
                    }
ALL's working well. but my requirement is to upload this file after it has been saved and i have to restrict it to 30kb(no suggestions to increase the size limit please) without compromising on the quality.
I have other doubts too>>
a. Why it is generating an exception in encoding my big resolution images. likely 43203240 ,80004448 image resolution..
Keep up the good work .Kinda need a reply soon please

p.s: resizing of width and height not allowed . Just need to compress the size by a compression ratio
May 21, 2014 at 8:07 AM
What kind of exception is being raised for images with a big resolution? And what do you mean by a 43203240 ,80004448 image resolution?

How do you want to restrict the image to 30kb? Do you want to upload an image with smaller dimensions?
May 21, 2014 at 8:29 AM
Edited May 21, 2014 at 8:31 AM
@dlemstra::
4320X3240 and 8000X4448.. and 10240X5760 these are some of the high resolution images where the exception at Write method occurs:
 "{ImageMagick.MagickDelegateErrorException: Magick: UnableToEncodeImageFile `C:\TempImages\BIGG RESOLUTION images\joker222.j2k' "
I dont want to change the dimensions @dlemstra. i saw there's a command line tool for ImageMagick whereby we can set the compression ratio. how should i do that using the library
May 21, 2014 at 8:34 AM
Can you add a link to one of your image you want to reduce do 30kb? Can you also post the command line commands that you use to reduce the file size to 30kb? Did you paste the whole exception message? I am missing a line number in our code. And can you post a link to one of your big resolution images?
May 21, 2014 at 9:07 AM
http://postimg.org/image/h75xptzcn/
(Link to my image)
tried in cmd>>
convert -compress JPEG2000 "source.jpg" "destination.j2k"
same exception>>>
convert.exe: unable to encode image file "destination.j2k" @error/jp2.c/WriteJP2Image/1038
May 21, 2014 at 8:15 PM
Edited May 21, 2014 at 8:20 PM
The exception is raised by the OpenJPEG library and this is caused because it cannot allocate more memory. I will have to do some more research to find a work around for this. Not sure if that is even possible.

And why do you think it is possible to compress a 4mb file to 3kb with OpenJPEG compression?
May 23, 2014 at 6:35 AM
Edited May 23, 2014 at 7:49 AM
i just downloaded openjpeg suite and compressed 18 mb bitmap files to 32kb...but the size is getting bigger and bigger when i convert bigger bitmap images like 30mb or 40 mb. i will ask my peer what he has done to achieve this and revert to you @dlmestra