Leslie Viljoen
5/29/2008 8:06:00 PM
On Thu, May 29, 2008 at 8:23 PM, Chris Metcalfe <contact@prognition.com> wrote:
> Sorry the above message posted prematurely.
>
> The code is as follows:
>
> if params[:thumbnail] !=nil && params[:thumbnail] != ""
> virtual_item.thumbnail = params[:thumbnail].read
> virtual_item.thumbnail_content_type =
> params[:thumbnail].content_type.chomp
> end
>
> Now the .read function read the image properly. However it is being
> stored in the database upside down. The rows of the image are flipped
> only vertically, which is strange, and not both vertically and
> horizontally backwards. I'm assuming that there is a some 'header'
> bytes which describe the image, then the actual pixel data list row by
> row. We are reading PNG files.
>
> The 3D rendering software outputs the images the right side up, but once
> they have been transfered and saved in the database they are upside
> down.
>
> Any ideas on how we can investigate whether the .read function is doing
> something strange or prove that truly the params[:thumbnail] parameter
> actually contains upside down data?
Can you save the data back from the database in a file and then look at a
hex dump of it? I assume you store the PNG file intact and are not trying
to interpret it at all?
If you can save the file you can look at the bytes using Hexer on Linux or
XVI32 on Windows, and compare the bytes to the PNG file.
If you are using Ruby under Windows there's one trick I know of:
binary files need 'binmode' to be set to true in order for them to be
read properly. But that probably wouldn't invert them.
Les