Slicing pluging (for web and whatnot)

Bug #169985 reported by Matt-harrison-users
16
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Inkscape
Confirmed
Wishlist
Unassigned
Nominated for 0.48.x by Jimmy Volatile
Nominated for Old by Jimmy Volatile

Bug Description

Attached is a plugin for slicing images.

Here's the process I've used for slicing web layout with Inkscape. Create
your webpage layout (set page units to "px", width/height appropriately and
snap to 1 pixel intervals. This should allow pixel perfect alignment). Then
create a new layer, naming it slices. Draw rectangles over the areas you
want to slice (set x,y,width,height to whole pixel values). Name these
rectangles using the Object Properties found in the right click contextual
menu (the saved images name will be based on that value, so name them
something like "header" instead of the default/non-useful "rect4312").

What the plugin then does is iterate over all of the rectangle definitions
found in the slice layer and set the opacity of the slice rectangle to 0.
(That allows you to make slightly transparent slices, which are easier to
deal with than invisible ones) It then creates pngs for every slice. After
completing the slicing, it then sets all the slice rectangles to red at 25%
opacity. To continue working on your design without having to deal with the
slices being selected, just "lock" the slice layer and your clicks should
fall through. You can also click the "eye" on the slice layer to not view
it.

== UPDATE ==
Latest version found at github http://github.com/mattharrison/Inkscape-Slicer-Extension

Revision history for this message
Matt-harrison-users (matt-harrison-users) wrote :
Revision history for this message
Ryan Lerch (ryanlerch) wrote :

There is no attachment.
Setting status to Invalid.

Changed in inkscape:
importance: Undecided → Unknown
status: New → Invalid
Revision history for this message
MenTaLguY (mental-deactivatedaccount) wrote :

Expand the "Bug attachments" pane; it's there.

Changed in inkscape:
importance: Unknown → Wishlist
status: Invalid → Confirmed
Revision history for this message
Ryan Lerch (ryanlerch) wrote :

reverting status back to NEW. i found the attachment...

Changed in inkscape:
importance: Wishlist → Unknown
status: Confirmed → New
Revision history for this message
matt (matt-harrison) wrote :

So is there any sort of process to get this included in the next release?

Revision history for this message
Ted Gould (ted) wrote :

The problem with this extension is that it doesn't provide a way for user interaction about overriding files that are already on the filesystem. This could be a distructive action that is not undoable, so therefore the user must be prompted on whether this should be done.

I think that the solution for this type of extension is to define a new type of extension, something like "Output Multiple" so that Inkscape can handle the interaction and ensure that the user is comfortable with destroying previous work.

Considering the state we're in (chill) for Inkscape 0.46, I think it's unlikely to make it for that version. But, I think that this new type of file handling has been requested by many other extension developers (HTML page I can thing of specifically) so it should be done. I'd be happy to mentor someone wanting to work on it.

Revision history for this message
matt (matt-harrison) wrote :

Thanks for your response Ted, I appreciate it.

Am assuming that the new file extension will require C++ coding? If it's only python I wish I had known sooner. I submitted this a while back and hadn't had any feedback on it.

Also how is this different than the existing "export->group to png" plugin that uses the same file overwriting behaviour?

Revision history for this message
Ted Gould (ted) wrote : Re: [Bug 169985] Re: Slicing pluging (for web and whatnot)

On Thu, 2007-12-20 at 05:58 +0000, matt wrote:
> Am assuming that the new file extension will require C++ coding? If
> it's only python I wish I had known sooner. I submitted this a while
> back and hadn't had any feedback on it.

Yeah, it's a C++ task. Sorry, I didn't notice it early.

> Also how is this different than the existing "export->group to png"
> plugin that uses the same file overwriting behaviour?

There are some bugs in Inkscape today...

  --Ted

Revision history for this message
John Cliff (johncliff) wrote :

I think if it behaves no worse with regards to over writing than the current png export code it should go in. Could we get it to flash a "existing images will be overwritten" ok/cancel dialog at the start of its run? (that can just be python right?)

Changed in inkscape:
importance: Unknown → High
milestone: none → 0.46
status: New → Confirmed
Revision history for this message
Bryce Harrington (bryce) wrote :

Jon Cliff's workaround sounds viable, although it sounds like Ted's approach would be more proper.

In any case, it's getting a bit too late in the process for adding new features to the codebase (if it required only scripting changes, we could make an exception, but it sounds like this will require some infrastructure work). So I'm dropping the milestone. Also, as this is a feature rather than a bug, I'm shifting it over to RFE's.

This feature sounds pretty damn cool though, so I hope y'all keep on it and get it in once it's fully baked. I bet a lot of web developers could make heavy use of this.

Changed in inkscape:
importance: High → Wishlist
milestone: 0.46 → none
Revision history for this message
matt (matt-harrison) wrote :

Is there an RFE for Ted's C++ task? I'd like this to be a dependency of that change.

Revision history for this message
matt (matt-harrison) wrote :

I have an updated version for .46 that uses etree (instead of minidom).

A few comments.

* There are still extensions that exhibit the same behavior that this was rejected for. ie Effects->Images->Extract One Image (no I'm not bitter ;) ) Should I file bugs for them?

* Still waiting for any info regarding the C++ task.

* Lacking the C++ task, perhaps I can workaround in pygtk. Is pygtk guaranteed to be on all inkscape platforms (ie is it a dependency)?

-matt

Revision history for this message
matt (matt-harrison) wrote :

I've uploaded this to github[0]. I'm still using it and would like to get it in.

WRT clobbering existing files, would it be okay to have a checkbox in the export dialog to overwrite existing files?

0 - http://github.com/mattharrison/Inkscape-Slicer-Extension

Revision history for this message
Jimmy Volatile (spam-useful) wrote :

To me a simple checkbox saying

-------------------------------------------------------------------
[ ] Overwrite existing files without question
-------------------------------------------------------------------

would help a lot.

Furthermore, if the overwrite option is unchecked, it would be necessary to have a confirm dialog for each file saying something like

----------------------------------------------------
File already exists. Overwrite?

[Yes] [Yes to all] [No] [No to all]
---------------------------------------------------

(Or something to that effect.)

Revision history for this message
Jimmy Volatile (spam-useful) wrote :

Another thing: How would I install this on Windows?

I tried putting the file in:
C:\Program Files\Inkscape\share\extensions

...but with no luck :(

The readme describes placing the scripts in ~/.inkscape/extensions but in the equivalent folder on Windows (C:\Documents and Settings\<username>\), there' no such folder. Creating or renaming a .folder is not possible either on Windows.

Revision history for this message
Jimmy Volatile (spam-useful) wrote :

Alternatively, if popping up a dialog is too hard, just provide a checkbox in the export dialog saying:
-------------------------------------------------------
[X] Overwrite existing files.
-------------------------------------------------------
It'd do the job, even if the user feedback would be non-existent. I'd be very happy for a simple solution like this rather than waiting for a proper confirm dialog solution.

Cheers and keep up the good work!

Revision history for this message
matt (matt-harrison) wrote :

Jimmy, I don't think I'll be able to do the per image dialog is a cross platform manner. If something like zenity shipped with gtk+ I would. Hence the checkbox idea. When I get some time I'll try and do that.

WRT windows. I don't really use windows, but I know the code has some linuxisms right now. I'll try and fix those. When you say "...but no luck", what happened? (Was that directory where the other extensions were on windows? Did it appear in the extension menu after a restart?)

Thanks for the feedback

Revision history for this message
matt (matt-harrison) wrote :

Code in github now has an overwrite option!

I've also changed the logging directory to be platform agnostic. Please give it a try!

Revision history for this message
bbyak (buliabyak) wrote :

Matt: how is it better than the "batch export selected objects" option in Export dialog? If it's better in some respects, maybe it's preferable to improve that option to match, instead of adding an extension?

Revision history for this message
matt (matt-harrison) wrote :

Thanks for the response, here's some comments:

  * Mine is explicit about where it saves the exports. (see bug https://bugs.launchpad.net/inkscape/+bug/411568 )
  * Mine is a little bit friendlier to web developers who may only want a rectangular portion of a drawing. The same technique basically works in both. Create another layer with the areas you want to export and export them. In the "batch export" the other rectangles need to be invisible, which is very bad for usability. My plugin ignores the actual color/alpha of the rectangles, so you can see what you are exporting. (Click hide layer if the color bothers you).
  * Batch export also clobbers, which was the original reason why this was rejected. Mine no longer clobbers.

In the end I think it would be appropriate for both to be in. I think mine is more intuitive and user friendly.

Revision history for this message
Alvin Penner (apenner) wrote :

could you attach a recent version of the source code to this bug report?
I am on Windows and I have not been able to get any useable code from the website http://github.com/mattharrison/Inkscape-Slicer-Extension after numerous tries.

Revision history for this message
matt (matt-harrison) wrote :

attatching mattharrison-Inkscape-Slicer-Extension-4fa68dc2c919c6e0ee868fdc67c3bbc7d2ca17c0.zip

Let me know if you have issues with it.

Revision history for this message
Jimmy Volatile (spam-useful) wrote :
Download full text (3.5 KiB)

Sorry. I know you were asking Matt but here's my reply to why slices is
often needed:

A typical web or application design consists of both foreground objects and
background objects. The foreground objects are typically icons, buttons and
similar where the area of the object = the area of the final .png-file.

The backgrounds are often exported in much larger areas which do not
correspond with the objects or groups that they are made up of. Slices allow
one to overcome this problem as one just define whatever rectangular areas
are required by the HTML-code or application and export those. Another
benefit is that the design can change quite independently of the slices. One
does not have to reapply the export-names to new design objects copied in
from other files. Conversely, with a proper slices system, it's also
possible to copy slice-sets between files thus allowing quick production of
new websites based on the same HTML-structure.

Now, the current problem with slices in Inkscape is that they are not
visible and there is only a DIY "hackaround" solution for slicing designs by
using a somewhat non-obvious workflow involving either tab-selecting
invisible slices and then exporting or switching a separate slices layer on,
selecting the slice and then switch it off again while retaining the
selection before finally exporting.

Making the final step towards some kind of visible, slectable and exportable
slices would make Inkscape better than most other well known slicing tools
out there since it supports both exporting slices *and* any named, selected
objects. This would be far better than Adobe Fireworks which only supports
one layer of slices but has *no* options for exporting single objects like
Inkscape does.

With regs,

Jimmy Volatile

On Fri, Sep 18, 2009 at 10:49 PM, bbyak <email address hidden> wrote:

> Matt: how is it better than the "batch export selected objects" option
> in Export dialog? If it's better in some respects, maybe it's preferable
> to improve that option to match, instead of adding an extension?
>
> --
> Slicing pluging (for web and whatnot)
> https://bugs.launchpad.net/bugs/169985
> You received this bug notification because you are a direct subscriber
> of the bug.
>
> Status in Inkscape: A Vector Drawing Tool: Confirmed
>
> Bug description:
> Attached is a plugin for slicing images.
>
> Here's the process I've used for slicing web layout with Inkscape. Create
> your webpage layout (set page units to "px", width/height appropriately and
> snap to 1 pixel intervals. This should allow pixel perfect alignment). Then
> create a new layer, naming it slices. Draw rectangles over the areas you
> want to slice (set x,y,width,height to whole pixel values). Name these
> rectangles using the Object Properties found in the right click contextual
> menu (the saved images name will be based on that value, so name them
> something like "header" instead of the default/non-useful "rect4312").
>
> What the plugin then does is iterate over all of the rectangle definitions
> found in the slice layer and set the opacity of the slice rectangle to 0.
> (That allows you to make slightly transparent slices, which are easier to
> deal with th...

Read more...

Revision history for this message
Jimmy Volatile (spam-useful) wrote :

Neither have I, I'm afraid.

I tried out the same code on both windows and Linux Mint yesterday but with
no luck....I'll try it out on my work system on Monday :)

Regs, Jimmy Volatile

On Sat, Sep 19, 2009 at 1:40 AM, Alvin Penner <email address hidden> wrote:

> could you attach a recent version of the source code to this bug report?
> I am on Windows and I have not been able to get any useable code from the
> website http://github.com/mattharrison/Inkscape-Slicer-Extension after
> numerous tries.
>
>
>

Revision history for this message
Jimmy Volatile (spam-useful) wrote :

It doesn't even show up in the Extensions-menu, this time, I'm afraid. I put
the script-files in ~/.inkscape/extensions, and started Inkscape as
instructed in the README, but nothing happened in the menus.

This may be due to that I'm running Inkscape translated to Norwegian. But
like mentioned earlier, I'll test this more on Monday.

Cheers and keep up the good work :)

On Sat, Sep 19, 2009 at 1:48 AM, matt <email address hidden> wrote:

> attatching mattharrison-Inkscape-Slicer-Extension-
> 4fa68dc2c919c6e0ee868fdc67c3bbc7d2ca17c0.zip
>
> Let me know if you have issues with it.
>
> ** Attachment added:
> "mattharrison-Inkscape-Slicer-Extension-4fa68dc2c919c6e0ee868fdc67c3bbc7d2ca17c0.zip"
>
> http://launchpadlibrarian.net/32045603/mattharrison-Inkscape-Slicer-Extension-4fa68dc2c919c6e0ee868fdc67c3bbc7d2ca17c0.zip
>
>
>

Revision history for this message
matt (matt-harrison) wrote :

I should note that it's telling that another user went ahead and re-wrote the script [0] when my older version didn't work on their machine. [0] That user either wanted similar behavior to mine, didn't like the batch export command or didn't know the batch export exists.

0 - http://ciantic.blogspot.com/2009/02/inkscape-slicer.html

I'll look into the installation stuff. I'm actually throwing my code into /usr/share/inkscape/extensions (gentoo location) directly. Though I've heard rumors that the ~ location works on Mac. I actually haven't tried it on linux.

Revision history for this message
Alvin Penner (apenner) wrote :

thanks, Matt, I believe it is working normally on Windows XP.
- I put the files into \Inkscape\share\extensions\
- I selected 2 rectangles and when I executed the extension the 2 rectangles turned a pinkish color.
- I specified '\' as the destination directory
- and I got 2 png files in the root directory as expected.

I can't really comment on the overall usefulness, because this is not what I normally do with Inkscape, but it does appear to be fully 'Windows-compatible', thanks Matt

Revision history for this message
su_v (suv-lp) wrote :

@Matt - which python version do you use on Gentoo? I have minor issues on OS x 10.5.8 with
- Inkscape 0.47pre2-2 r22153, Python 5.2.1
- Inkscape 0.46+devel r22240, Python 2.6.2

1) I get the console messages from Inkscape shown in an extension error dialog - even though the sliced export (and logging to $TMP/inklog.log) work as expected...

error messages from layer2png.py:

Xlib: extension "RANDR" missing on display "/tmp/launch-Dc2T4w/:0".

** (inkscape-bin:11502): WARNING **: Format autodetect failed. The file is being opened as SVG.
Xlib: extension "RANDR" missing on display "/tmp/launch-Dc2T4w/:0".

** (inkscape-bin:11536): WARNING **: Format autodetect failed. The file is being opened as SVG.
Xlib: extension "RANDR" missing on display "/tmp/launch-Dc2T4w/:0".

** (inkscape-bin:11570): WARNING **: Format autodetect failed. The file is being opened as SVG.
Xlib: extension "RANDR" missing on display "/tmp/launch-Dc2T4w/:0".

** (inkscape-bin:11604): WARNING **: Format autodetect failed. The file is being opened as SVG.

Can you redirect or dump stderr as other extensions do (they never show the console error output of the command-line inkscape invocation)? Maybe a naive question as I am a Python ignoramus…

corresponding inklog.log lines (note: the temp-files don't have an .svg suffix - hence above error msgs):

DEBUG:root:COMMAND inkscape -i rect2891 -e /Users/suv/rect2891.png /var/folders/Bx/Bx+++TQ/-Tmp-/ink_ext_XXXXXX.svg6RTV0U
DEBUG:root:COMMAND inkscape -i rect2893 -e /Users/suv/rect2893.png /var/folders/Bx/Bx+++TQ/-Tmp-/ink_ext_XXXXXX.svg6RTV0U
DEBUG:root:COMMAND inkscape -i rect2895 -e /Users/suv/rect2895.png /var/folders/Bx/Bx+++TQ/-Tmp-/ink_ext_XXXXXX.svg6RTV0U
DEBUG:root:COMMAND inkscape -i rect2897 -e /Users/suv/rect2897.png /var/folders/Bx/Bx+++TQ/-Tmp-/ink_ext_XXXXXX.svg6RTV0U

2) the string 'none' in your 'inx' file is taken literally on OS X as directory "none" instead of value=None. The extractimages.py extension has the same issue... Deleting the string in the inx file lets your extension default to $HOME as export directory.

3) BTW - OS X user extension installation path: ~/.config/inkscape/extensions/

Revision history for this message
su_v (suv-lp) wrote :

…and

4) your 'inx' file needs a new XML and namespace declaration for Inkscape 0.47 - see the changes to *.inx in revision 18364
   <http://inkscape.svn.sourceforge.net/viewvc/inkscape?view=rev&revision=18364>

hth, ~suv

Revision history for this message
matt (matt-harrison) wrote :

thx suv!

Both are fixed in github

Revision history for this message
su_v (suv-lp) wrote :

Fixes confirmed with Inkscape 0.46+devel r22240 on OS X 10.5.8:

1) stderr no longer sent back to Inkscape
2) export directory defaults to $HOME (does 'default=os.path.expanduser("~")' work on Windows as well?) Maybe add a short comment (or tab with description as e.g. the 'Measure Path…' extension does) to the 'Export Layer Slices' dialog?

Thank you for your efforts!

p.s. I only tested basic functionality (3 shapes on page, exported in 4 slices, export to '' (i.e. '~'), overwrite on/off)

Revision history for this message
matt (matt-harrison) wrote :

Cool thanks for testing. I've also:
  * confirmed that it works in ~/.config/inkscape/extensions
  * removed live preview option
  * added help tab
  * moved from "Export" to "Web" in Extensions menu

Revision history for this message
su_v (suv-lp) wrote :

oops - error:

> Usage: layer2png.py [options] SVGfile
>
> layer2png.py: error: no such option: --tab

layer2png.py is missing something like (copied from measure.py):

        self.OptionParser.add_option("--tab",
                        action="store", type="string",
                        dest="tab", default="sampling",
                        help="The selected UI-tab when OK was pressed")

Revision history for this message
Jimmy Volatile (spam-useful) wrote :

I can confirm this. Whatever is written as the path in the export dialog,
the script fails with an error message saying:

"Usage: layer2png.py [options] SVGfile

layer2png.py: error: no such option: --tab"

Nothing is exported and the slices do not turn pink.

Kind regs, Jimmy Volatile

On Sun, Sep 20, 2009 at 8:05 AM, ~suv <email address hidden> wrote:

> oops - error:
>
> > Usage: layer2png.py [options] SVGfile
> >
> > layer2png.py: error: no such option: --tab
>
> layer2png.py is missing something like (copied from measure.py):
>
> self.OptionParser.add_option("--tab",
> action="store", type="string",
> dest="tab", default="sampling",
> help="The selected UI-tab when OK was pressed")
>
>

Revision history for this message
Jimmy Volatile (spam-useful) wrote :

Sorry! Forgot to mention that I've put my script into

~/.config/inkscape/extensions/

Revision history for this message
matt (matt-harrison) wrote :

whoops, pushed fix...

Revision history for this message
su_v (suv-lp) wrote :

fix confirmed on OS X

BTW - (in case you like coding more then slicing ;-) - while a confirm dialog for each file to overwrite isn't easily possible in a cross-platform manner, you could use errormsg(msg) from inkex.py[*] to notify the user either of
a) files overwritten, or
b) slices not exported if [overwrite existing exports] is not checked

Even more elegant would be to change the color of the slices according to their most recent export status (e.g. green - exported (new file), grey - not exported (file exists), red - exported (file overwritten))…

anyway, thank you for the recent updates, ~suv

[*] e.g. draw_from_triangle.py reports the triangle properties with inkex.errormsg(_(…))

Revision history for this message
matt (matt-harrison) wrote :

nice ideas ~suv. Pushed update with the color changing. I don't particularly care for a popup indicating that you overwrote files. It seems too windows'y for me. And there's not much I can do at that point. Plus if I'm worried about that I'm either checking my image into revision control or handling exports more carefully.

Revision history for this message
Jimmy Volatile (spam-useful) wrote :

Fix confirmed on Linux Mint 7 (based on Ubuntu 9.04), Ubuntu 9.04 (when I
finally found out where to put the extension) and Windows XP.

I'll try out the very latest fix with the colour slice feedback on at least
WinXP and possibly Ubuntu and confirm if that works as well.
I'll be using the script for the next two design jobs now so I'll really be
able to put it to the test. Thanks for the good work.

On Sun, Sep 20, 2009 at 2:42 PM, matt <email address hidden> wrote:

> whoops, pushed fix...
>
> --
> Slicing pluging (for web and whatnot)
> https://bugs.launchpad.net/bugs/169985
> You received this bug notification because you are a direct subscriber
> of the bug.
>
> Status in Inkscape: A Vector Drawing Tool: Confirmed
>
> Bug description:
> Attached is a plugin for slicing images.
>
> Here's the process I've used for slicing web layout with Inkscape. Create
> your webpage layout (set page units to "px", width/height appropriately and
> snap to 1 pixel intervals. This should allow pixel perfect alignment). Then
> create a new layer, naming it slices. Draw rectangles over the areas you
> want to slice (set x,y,width,height to whole pixel values). Name these
> rectangles using the Object Properties found in the right click contextual
> menu (the saved images name will be based on that value, so name them
> something like "header" instead of the default/non-useful "rect4312").
>
> What the plugin then does is iterate over all of the rectangle definitions
> found in the slice layer and set the opacity of the slice rectangle to 0.
> (That allows you to make slightly transparent slices, which are easier to
> deal with than invisible ones) It then creates pngs for every slice. After
> completing the slicing, it then sets all the slice rectangles to red at 25%
> opacity. To continue working on your design without having to deal with the
> slices being selected, just "lock" the slice layer and your clicks should
> fall through. You can also click the "eye" on the slice layer to not view
> it.
>

Revision history for this message
matt (matt-harrison) wrote :

I realize people are probably busy with the .47 release now. However, I'd like to know what is needed for this to be included in .48. Bryce? Ted? Anyone?

su_v (suv-lp)
tags: added: exporting extensions-plugins png
removed: color
matt (matt-harrison)
description: updated
Revision history for this message
matt (matt-harrison) wrote :

ping for .48 release???!!!

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.