Giter Site home page Giter Site logo

Saving SD info to images about sd-parsers HOT 2 CLOSED

d3x-at avatar d3x-at commented on July 21, 2024
Saving SD info to images

from sd-parsers.

Comments (2)

Automaticism avatar Automaticism commented on July 21, 2024 1

Thanks for your reply. This was mostly when thinking about having the option of converting images to jpgs to save space while keeping the metadata.

The solution in your example will suffice to accomplish what I was thinking about 👌

from sd-parsers.

d3x-at avatar d3x-at commented on July 21, 2024

Having looked at your project, i am not sure what exactly you are trying to do, so feel free to correct me when i am going into the wrong direction with this answer.

Generally, i don't see much benefit in adding saving functionality to my library, as the Pillow library handles this pretty well already. Mixing in the sd-parsers library into this is also not a problem, as you can see in the example below:

from PIL import Image
from PIL.PngImagePlugin import PngInfo
from sdparsers import ParserManager

parser = ParserManager()

with Image.open("test.png") as image:
    # read data here
    data = parser.parse(image)
    # do stuff with data
    ....

    # then write some data
    if image.format == "PNG":
        png_info = PngInfo()

        # add the metadata from the opened image
        for key, value in image.text.items():
            png_info.add_text(key, value)

        # then add your custom key
        png_info.add_text("my-custom-key", "my-custom-value")

        # save
        image.save("test_out.png", pnginfo=png_info)

I personally though, would advise against writing metadata back into images in any form if you can avoid it, as (as with any file operation) there is always the chance of something going wrong.

from sd-parsers.

Related Issues (2)

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.