It is currently Mon Apr 15, 2024 8:05 am


All times are UTC - 5 hours [ DST ]


Switch to mobile style

Post new topic Reply to topic  [ 22 posts ]  Go to page Previous  1, 2
Author Message
 Post subject: Re: Bar code script or filter
PostPosted: Mon Jun 20, 2016 2:20 am  (#21) 
Offline
GimpChat Member
User avatar

Joined: Jan 13, 2011
Posts: 2238
Location: Poland
Attachment deleted - it was a failed attempt to create a plugin.
For me, it works well.

For coders who want to experiment with the code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# This plugin is based on:
# Zint Barcode Generator 2.4.3 https://sourceforge.net/projects/zint/?source=navbar
# Resize with ImageMagick.py V1 - (c) Berthold Hinz 2010
# ==============================================================================
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, version 3 of the License.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
# ==============================================================================

from gimpfu import *
import shlex
import subprocess
import os, sys
import tempfile

def barcode(img, layer, type, format, path1, path2, height, space, border, fg, text, rem):
    pdb.gimp_image_undo_group_start(img)
    tempimage = pdb.gimp_image_duplicate(img)
   
    if format=="png":
        tempfilename = pdb.gimp_temp_name("png")
    else:
        tempfilename = pdb.gimp_temp_name("svg")
    tempdrawable = pdb.gimp_image_get_active_drawable(tempimage)
    pdb.gimp_progress_set_text ("Saving a copy")
   
    if format=="png":
      pdb.gimp_file_save(tempimage, tempdrawable, tempfilename, "")
    else:
      pdb.gimp_vectors_export_to_file(tempimage, tempfilename, None)
   
    cmd="zint "
    cmd=cmd+ "-o"+tempfilename + " -b "+str(type) + " --height="+str(height) + " -w"+str(space) + " --box --border="+str(border) + " --fg="+str(fg) + " -d "+'"'+str(text)+'"'
    args = shlex.split(cmd)
    p = os.popen(cmd)
    pdb.gimp_progress_set_text ("calling Zint 2.4.3...")
    pdb.gimp_progress_pulse()
    child = subprocess.Popen(args, shell=False)
    child.communicate()

    newlayer = pdb.gimp_file_load_layer(img, tempfilename)
    img.add_layer(newlayer,-1)

    if format=="svg":
      pdb.gimp_vectors_import_from_file(img, tempfilename, path1, path2)
    if rem:
        os.remove(tempfilename)
        gimp.delete(tempimage)
    pdb.gimp_image_undo_group_end(img)
    gimp.displays_flush()      


register(
    "python-fu-barcode",
    "Barcode Zint for GIMP\n\nNUMERIC VALUE -  Barcode Name:\n\n   9 - Extended Code\n 20 - Code 128\n 23 - Code 16K\n 24 - Code 49\n 25 - Code 93\n 35 - Telpen Alpha\n 57 - Maxicode\n 58 - QR Code\n 71 - Data Matrix\n 84 - MicroPDF417\n 92 - Aztec Code\n 97 - Micro QR Code\n141 - Code One\n142 - Grid Matrix",
    "Barcode based by Zint v.2.0",
    "MareroQ",
    "GPL",
    "2016",
    "<Image>/Filters/Render/Barcode Zint...",
    "",
   [
   (PF_INT, "type", ("Type barcode (numeric value) :"), "20"),
   (PF_RADIO, "format", ("Format barcode (temp) :"), "png", (("PNG", "png"),("SVG :", "svg"))),
   (PF_BOOL, "path1", "Merge paths into a single vectors object : ", False),
   (PF_BOOL, "path2", "Scale the SVG to image dimensions : ", False),
   (PF_INT, "height", ("Adjusting height :"), "10"),
   (PF_INT, "space", ("Adjusting whitespace (left and right) :"), "0"),
   (PF_INT, "border", ("Adding boundary bars and boxes :"), "0"),
   (PF_STRING, "fg", "Color FG (HTML):", "000000"),
   (PF_STRING, "text", "Text (only Latin-1) :", "Test123"),
   (PF_BOOL, "rem_1", ("Delete temp file? "), True)
   ],
    [],
    barcode)
main()

_________________
Image

Slava
Ukraini!


Top
 Post subject: Re: Bar code script or filter
PostPosted: Mon Jun 20, 2016 3:27 pm  (#22) 
Offline
GimpChat Member
User avatar

Joined: Jul 04, 2010
Posts: 2253
Location: Retired Moderator Slowly Returning to the Living.
PhotoMaster wrote:
These seem to be pretty nice! A couple came up with a blank white layer, but I'll play to figure out why. I wish it would allow you to make the QR Codes larger. If I increase the size of the image, it gets blurry. SVG has been throwing some errors.


I got it!! I set the Format barcode (temp) to SVG and clicked on Scale the SVG to image dimensions. I have to keep Merge paths into a single vector object turned OFF, or the plugin blows up. I manually merge the resulting paths into a single path by shift clicking the eye on any one path and then right click and select Merge visible paths. I make a selection from the path, invert the selection and fill it on a new layer.

Attachment:
NewBarCodeTest.jpg
NewBarCodeTest.jpg [ 256.3 KiB | Viewed 949 times ]

_________________
Artists aren't crazy! We're eccentric! ~G.M. Ross

Image

My Sigs = My Photos
Check out my work at http://www.flickr.com/photos/photomastergreg.


Top
Post new topic Reply to topic  [ 22 posts ]  Go to page Previous  1, 2

All times are UTC - 5 hours [ DST ]


   Similar Topics   Replies 
No new posts Attachment(s) Inserting pdb.python_gegl command in my code

21

No new posts VS Code - configure linting for PythonFu

0

No new posts Attachment(s) Kaleidoscope Plugin Source Code

1

No new posts Attachment(s) Source Code for all my GEGL Filters

31

No new posts timer plug-in acts sort of like a stop watch w/wo TRACKING CODE

1



* Login  



Powered by phpBB3 © phpBB Group