different updates and new psd export extension

This commit is contained in:
Mario Voigt 2021-10-23 21:31:58 +02:00
parent 27acd10c8a
commit 3901479ab2
11 changed files with 232 additions and 8 deletions

View File

@ -1,6 +1,6 @@
# MightyScape for Inkscape 1.0+
In short: A maintained extension collection for Inkscape 1.0+, working on Windows and Linux. There are **228 extension folders** with **399 .inx files** inside. We also take part at https://inkscape.org/gallery/=extension/ (with single extension uploads).
In short: A maintained extension collection for Inkscape 1.0+, working on Windows and Linux. There are **231 extension folders** with **402 .inx files** inside. We also take part at https://inkscape.org/gallery/=extension/ (with single extension uploads).
# About MightyScape

View File

@ -3,6 +3,7 @@
<name>Duplicate + Reverse + Join</name>
<id>fablabchemnitz.de.duplicate_reverse_join</id>
<effect>
<object-type>path</object-type>
<effects-menu>
<submenu name="FabLab Chemnitz">
<submenu name="Modify existing Path(s)"/>

View File

@ -8,12 +8,12 @@
<option value="cm">cm</option>
<option value="m">m</option>
</param>
<label appearance="heder">Threshold</label>
<label appearance="header">Threshold</label>
<param name="min_filter_enable" type="bool" gui-text="Enable filtering min.">false</param>
<param name="min_threshold" type="float" min="0.000" precision="3" max="10000000.000" gui-text="Min.">1.000</param>
<param name="max_filter_enable" type="bool" gui-text="Enable filtering max.">false</param>
<param name="max_threshold" type="float" min="0.000" precision="3" max="10000000.000" gui-text="Max.">10000000.000</param>
<label appearance="heder">Equation</label>
<param name="max_threshold" type="float" min="0.000" precision="3" max="10000000.000" gui-text="Max.">10000000.000</param>
<label appearance="header">Equation</label>
<param name="measure" type="optiongroup" appearance="combo" gui-text="Measure by">
<option value="length">Length (Unit)</option>
<option value="area">Area (Unit^2)</option>

View File

@ -10,7 +10,6 @@ class LaserCheck(inkex.EffectExtension):
'''
check for old styles which should be upgraded
border around complete content
'''
#def add_arguments(self, pars):

View File

@ -10,7 +10,7 @@
"comment": "",
"source_url": "https://gitea.fablabchemnitz.de/FabLab_Chemnitz/mightyscape-1.X/src/branch/master/extensions/fablabchemnitz/laser_check",
"fork_url": null,
"documentation_url": "",
"documentation_url": "https://stadtfabrikanten.org/display/IFM/Laser+Check",
"inkscape_gallery_url": null,
"main_authors": [
"github.com/vmario89"

View File

@ -0,0 +1,20 @@
[
{
"name": "Photoshop PSD Export",
"id": "fablabchemnitz.de.psd_export",
"path": "psd_export",
"original_name": "GIMP PSD",
"original_id": "org.ekips.output.gimp_psd",
"license": "GNU GPL v2",
"license_url": "https://github.com/junichi11/gimp_psd/blob/master/gimp_psd.py",
"comment": "",
"source_url": "https://gitea.fablabchemnitz.de/FabLab_Chemnitz/mightyscape-1.X/src/branch/master/extensions/fablabchemnitz/psd_export",
"fork_url": "https://github.com/junichi11/gimp_psd",
"documentation_url": "https://stadtfabrikanten.org/pages/viewpage.action?pageId=120525412",
"inkscape_gallery_url": null,
"main_authors": [
"github.com/junichi11",
"github.com/vmario89"
]
}
]

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
<name>Photoshop PSD Export</name>
<id>fablabchemnitz.de.psd_export</id>
<param name="guides" type="bool" gui-text="Save Guides">false</param>
<param name="grid" type="bool" gui-text="Save Grid">false</param>
<param name="background" type="bool" gui-text="Save background color">false</param>
<param name="dpi" type="float" min="1" max="3000" gui-text="File Resolution">96</param>
<output>
<extension>.psd</extension>
<mimetype>application/x-psd</mimetype>
<filetypename>Photoshop PSD (*.psd)</filetypename>
<filetypetooltip>Photoshop PSD (*.psd)</filetypetooltip>
<dataloss>true</dataloss>
</output>
<script>
<command location="inx" interpreter="python">psd_export.py</command>
<helper_extension>org.inkscape.output.svg.inkscape</helper_extension>
</script>
</inkscape-extension>

View File

@ -0,0 +1,179 @@
#!/usr/bin/env python3
#
# Copyright (C) 2006 Aaron Spike, aaron@ekips.org
# Copyright (C) 2010-2012 Nicolas Dufour, nicoduf@yahoo.fr
# (Windows support and various fixes)
#
# 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; either version 2 of the License, or
# (at your option) any later version.
#
# 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, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
"""
Export to Gimp's XCF file format including Grids and Guides.
"""
import os
from collections import OrderedDict
import inkex
from inkex.base import TempDirMixin
from inkex.command import take_snapshot, call
from inkex.localization import inkex_gettext as _
class PSDExport(TempDirMixin, inkex.OutputExtension):
"""
Provide a quick and dirty way of using gimp to output an xcf from Inkscape.
Both Inkscape and Gimp must be installed for this extension to work.
"""
dir_prefix = 'gimp-out-'
def add_arguments(self, pars):
pars.add_argument("--tab")
pars.add_argument("-d", "--guides", type=inkex.Boolean, help="Save Guides")
pars.add_argument("-r", "--grid", type=inkex.Boolean, help="Save Grid")
pars.add_argument("-b", "--background", type=inkex.Boolean, help="Save background color")
pars.add_argument("-i", "--dpi", type=float, default=96.0, help="File resolution")
def get_guides(self):
"""Generate a list of horzontal and vertical only guides"""
horz_guides = []
vert_guides = []
# Grab all guide tags in the namedview tag
for guide in self.svg.namedview.get_guides():
if guide.is_horizontal:
# GIMP doesn't like guides that are outside of the image
if 0 < guide.point.y < self.svg.height:
# The origin is at the top in GIMP land
horz_guides.append(str(guide.point.y))
elif guide.is_vertical:
# GIMP doesn't like guides that are outside of the image
if 0 < guide.point.x < self.svg.width:
vert_guides.append(str(guide.point.x))
return ('h', ' '.join(horz_guides)), ('v', ' '.join(vert_guides))
def get_grid(self):
"""Get the grid if asked for and return as gimpfu script"""
scale = (self.svg.scale) * (self.options.dpi / 96.0)
# GIMP only allows one rectangular grid
xpath = "sodipodi:namedview/inkscape:grid[@type='xygrid' and (not(@units) or @units='px')]"
if self.svg.xpath(xpath):
node = self.svg.getElement(xpath)
for attr, default, target in (('spacing', 1, 'spacing'), ('origin', 0, 'offset')):
fmt = {'target': target}
for dim in 'xy':
# These attributes could be nonexistent
unit = float(node.get(attr + dim, default))
unit = self.svg.uutounit(unit, "px") * scale
fmt[dim] = int(round(float(unit)))
yield '(gimp-image-grid-set-{target} img {x} {y})'.format(**fmt)
@property
def docname(self):
"""Get the document name suitable for export"""
return self.svg.get('sodipodi:docname') or 'document'
def save(self, stream):
pngs = OrderedDict()
valid = False
for node in self.svg.xpath("/svg:svg/*[name()='g' or @style][@id]"):
if not len(node): # pylint: disable=len-as-condition
# Ignore empty layers
continue
valid = True
node_id = node.get('id')
name = node.get("inkscape:label", node_id)
pngs[name] = take_snapshot(
self.document,
dirname=self.tempdir,
name=name,
dpi=int(self.options.dpi),
export_id=node_id,
export_id_only=True,
export_area_page=True,
export_background_opacity=int(bool(self.options.background))
)
if not valid:
inkex.errormsg(_('This extension requires at least one non empty layer.'))
return
xcf = os.path.join(self.tempdir, "{}.psd".format(self.docname))
script_fu = """
(tracing 1)
(define
(png-to-layer img png_filename layer_name)
(let*
(
(png (car (file-png-load RUN-NONINTERACTIVE png_filename png_filename)))
(png_layer (car (gimp-image-get-active-layer png)))
(xcf_layer (car (gimp-layer-new-from-drawable png_layer img)))
)
(gimp-image-add-layer img xcf_layer -1)
(gimp-drawable-set-name xcf_layer layer_name)
)
)
(let*
(
(img (car (gimp-image-new 200 200 RGB)))
)
(gimp-image-set-resolution img {dpi} {dpi})
(gimp-image-undo-disable img)
(for-each
(lambda (names)
(png-to-layer img (car names) (cdr names))
)
(map cons '("{files}") '("{names}"))
)
(gimp-image-resize-to-layers img)
""".format(
dpi=self.options.dpi,
files='" "'.join(pngs.values()),
names='" "'.join(list(pngs))
)
if self.options.guides:
for dim, guides in self.get_guides():
script_fu += """
(for-each
(lambda ({d}Guide)
(gimp-image-add-{d}guide img {d}Guide)
)
'({g})
)""".format(d=dim, g=guides)
# Grid
if self.options.grid:
for fu_let in self.get_grid():
script_fu += "\n" + fu_let + "\n"
script_fu += """
(gimp-image-undo-enable img)
(file-psd-save RUN-NONINTERACTIVE img (car (gimp-image-get-active-layer img)) "{xcf}" "{xcf}" 0 0))
(gimp-quit 0)
""".format(xcf=xcf)
#please install with apt/dnf to install gimp. Do not use snap or flatpak installations
call('gimp', "-b", "-", i=True, batch_interpreter="plug-in-script-fu-eval", stdin=script_fu)
with open(xcf, 'rb') as fhl:
stream.write(fhl.read())
if __name__ == '__main__':
PSDExport().run()

View File

@ -5,7 +5,9 @@
<effect>
<object-type>all</object-type>
<effects-menu>
<submenu name="Images"/>
<submenu name="FabLab Chemnitz">
<submenu name="Various"/>
</submenu>
</effects-menu>
</effect>
<script>

View File

@ -54,7 +54,8 @@
<vbox>
<param name="metadata" type="bool" gui-text="metadata">true</param>
<param name="pattern" type="bool" gui-text="pattern">true</param>
<param name="script" type="bool" gui-text="script">true</param>
<param name="script" type="bool" gui-text="script">true</param>
<param name="style" type="bool" gui-text="style">true</param>
<param name="switch" type="bool" gui-text="switch">true</param>
<param name="symbol" type="bool" gui-text="symbol">true</param>
<param name="use" type="bool" gui-text="use">true</param>

View File

@ -62,6 +62,7 @@ class UngrouperAndElementMigratorFilter(inkex.EffectExtension):
pars.add_argument("--script", type=inkex.Boolean, default=True)
pars.add_argument("--symbol", type=inkex.Boolean, default=True)
pars.add_argument("--stop", type=inkex.Boolean, default=True)
pars.add_argument("--style", type=inkex.Boolean, default=True)
pars.add_argument("--switch", type=inkex.Boolean, default=True)
pars.add_argument("--use", type=inkex.Boolean, default=True)
pars.add_argument("--flowRoot", type=inkex.Boolean, default=True)
@ -98,6 +99,7 @@ class UngrouperAndElementMigratorFilter(inkex.EffectExtension):
namespace.append("{http://www.w3.org/2000/svg}mask") if self.options.mask else ""
namespace.append("{http://www.w3.org/2000/svg}metadata") if self.options.metadata else ""
namespace.append("{http://www.w3.org/2000/svg}stop") if self.options.stop else ""
namespace.append("{http://www.w3.org/2000/svg}style") if self.options.style else ""
namespace.append("{http://www.w3.org/2000/svg}switch") if self.options.switch else ""
namespace.append("{http://www.w3.org/2000/svg}use") if self.options.use else ""
namespace.append("{http://www.w3.org/2000/svg}flowRoot") if self.options.flowRoot else ""