Coder Social home page Coder Social logo

Comments (4)

tatarize avatar tatarize commented on June 10, 2024 1

This issue was about writing the transparency so the images could be put over other images, not changing the default mode.

You'd actually just need to check at the end before writing to JPG and convert it to RGB at the last second.
image = image.convert('RGB')

Then you'd have the best of both worlds. Also, since the barcodes are actually 2 color, you could also save them out as 2 bit pngs either palette, or black&white, which would make them much smaller in size.

from python-barcode.

tatarize avatar tatarize commented on June 10, 2024

That code actually is allowed as an input and works correctly. The only thing that would need to be changed is the initialization of the image mode to RGBA. Rather than RGB.

class ImageWriterWithTransparency(ImageWriter):
    def _init(self, code):
        from PIL import Image, ImageDraw
        size = self.calculate_size(len(code[0]), len(code), self.dpi)
        self._image = Image.new("RGBA", size, self.background)
        self._draw = ImageDraw.Draw(self._image)

Use that as a your ImageWriter and you'll get transparencies.

from python-barcode.

WhyNotHugo avatar WhyNotHugo commented on June 10, 2024

I'm tempted to just change the default to RGBA.

Just have to double check it won't break any existing setup (I can't think of any though, since the default is still white).

from python-barcode.

WhyNotHugo avatar WhyNotHugo commented on June 10, 2024

Won't change the default since that would break JPEG, bug adding a parameter to use RGBA.

from python-barcode.

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.