Git Product home page Git Product logo

Comments (9)

eflister avatar eflister commented on July 30, 2024

definitely. not only that, but files load into a DynamicImage, and then i have to patternmatch on all those constructors to get an Image that i can imageWidth, etc on. why isn't DynamicImage a typeclass instead?

from juicy.pixels.

eflister avatar eflister commented on July 30, 2024

also, instead of a bunch of save* functions, why isn't file type an argument?
saveImage :: FilePath -> ImageType -> DynamicImage -> IO ()

data ImageType = PNG | JPG Int | BMP ...

from juicy.pixels.

Twinside avatar Twinside commented on July 30, 2024

DynamicImage can't be a type class, as the image decoders don't know at compilation time which color space the will have to decode (especially for the PNG case). For your use case, it's easy to add a function of the following type

{-# LANGUAGE Rank2Types #-}
withDynamicImage :: (foral pixel. Image pixel -> a) -> DynamicImage -> a

allowing something like withDynamicImage imageWidth

For the saveImage, I don't see any real advantage of providing it as the intended use case is to serialize to a fixed image format, but patches are welcome.

from juicy.pixels.

eflister avatar eflister commented on July 30, 2024

i'm not clear why your reason precludes a typeclass, but i might be missing something. is there any way to write withDynamicImage without a million patternmatches (which is just doing what a typeclass would do, but in a closed/brittle way)? in any case, why not include it in the library?

regarding saveImage, consider the use case (mine) of writing a thumbnailer -- doesn't care what the original format was, just wants to write out the same format. don't you want to let me write that in a generic way?

from juicy.pixels.

Twinside avatar Twinside commented on July 30, 2024

I don't know how to write decodeImage :: B.ByteString -> Either String DynamicImage with a type class, with the constraint that the caller doesn't know the pixel type (because it can only be known by the decoding function).

For the withDynamicImage, it's the lack of type mainly, but I accept pull requests.

For your specific use case, why not use the imageTo* functions? It seems to me that it answer your use case.

from juicy.pixels.

 avatar commented on July 30, 2024

Since this issue is a bit old, is there any way to determine image width from a dynamic image with a function call? (And your link to imageTo functions seems to have gone dead.)

from juicy.pixels.

Twinside avatar Twinside commented on July 30, 2024

The dynamicMap could help extract width and height of a fully extracted image, I've updated the link to the imageTo functions

from juicy.pixels.

 avatar commented on July 30, 2024

Thanks, that was perfect.

from juicy.pixels.

Twinside avatar Twinside commented on July 30, 2024

Done with addition of Metadata.

from juicy.pixels.

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.