[GM-help] Re: [GM-core] please help about fileSize() function
Swiss army knife of image processing
Brought to you by:
bfriesen
From: Bob F. <bfr...@si...> - 2005-03-04 23:44:10
|
On Thu, 3 Mar 2005, alessandro bonvicini wrote: > HI all, > first of all I would like to thanks all of you for the really wonderfull work > done in graphics magicks. > I am new to the library but I am very impressed from the features. > > I need your help because I don't understnd the behavior of the fileSize() > function. I believe that fileSize() will only produce a correct result based on the last read() or ping() operation. It does not return the size of the image just written. > In my program I need to know the dimension of the file in which the image > will be written BEFORE the call to > image.write, for streaming purpose. > How can I do this? Is it possibile? The problem is that the file format encoder has responsibility for encoding the file. When the file format is compressed, it is impossible to know the final file size without performing the encoding. For uncompressed files, it is often possible to accurately estimate the final file size. Even for uncompressed files, there may be associated metadata which takes up extra space, or there may be thresholds to encoding options (e.g. the number of bits used) which cause some images to take more space per pixel than others. > And why the fileSize() returned in the end is different from what it is > written on disk? It is apparently some random value at that point. If you absolutely need to know the file size prior to streaming, then you can write to a temporary file, or write the image to an in-memory Blob, and then stream the temporary file or Blob to the client. If the image is not too large, writing to an in-memory Blob is usually fastest. Bob ====================================== Bob Friesenhahn bfr...@si..., http://www.simplesystems.org/users/bfriesen/ GraphicsMagick Maintainer, http://www.GraphicsMagick.org/ |