Giter Club home page Giter Club logo

Comments (6)

wvanbergen avatar wvanbergen commented on June 11, 2024

After parsing the RGB stream, the resulting Canvas has #width and #height that you can call

from chunky_png.

TW-D avatar TW-D commented on June 11, 2024

Thanks wvanberge but i wasn't specific enough. Here is the code :

require('chunky_png')
include(ChunkyPNG)

# Constants

RGB_SIZE = 6

binary = File.open('./data', 'rb')
hexStream = ""
binary.each_char() do |char|
    hexStream += char.unpack('H*').join()
end
binary.close()

rgbStream = hexStream.scan(/.{#{RGB_SIZE}}/)

if (rgbStream.last().size() === RGB_SIZE)

    # how to calculate the correct width and height ?
    ChunkyPNG::Canvas.from_rgb_stream(74, 74, [rgbStream.join()].pack('H*')).save('./test.png')

end

from chunky_png.

wvanbergen avatar wvanbergen commented on June 11, 2024

You can't calculate those: an RGB strean is just a stream of pixels, so there's no way to know whether a stream of 4 pixels is a 1x4 image or a 2x2. This is why you have to supply these arguments.

from chunky_png.

TW-D avatar TW-D commented on June 11, 2024

If we know the number of pixels in an image of 1x1 it can not help me, according to the DPI used by 'ChunkyPNG::Canvas' ?

from chunky_png.

wvanbergen avatar wvanbergen commented on June 11, 2024

from_rgb_stream basically is: "please construct a canvas of this size, and use this pixeldata for it."

If you know the image is 1x1, you can use 1, 1 as first two arguments to from_rgb_stream. The RGB stream for the third argument should then be 3 bytes long.

from chunky_png.

TW-D avatar TW-D commented on June 11, 2024

Thank you very much, "chunky_png" is an elegant solution.

from chunky_png.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.