layers-slices - A slicing tool based on layers instead of guidelines

This script is meant to cut an image is smaller pieces and save these images automatically based on the size and names of specific layers, images to be used in web layouts.

Other options I found are based on guidelines. This approach has 2 drawbacks for me :

  • Image used for web layout are not always a pure table. The image you needfor the banner has not the same width than the one you need for the side block, and there are "cells" of that table that you don't need
  • It's saved with an autogenerated name

If I'm wrong with this analysis, tell me...  this script is perhaps a bad duplicate of some existing plugin I don't know about...

The idea here is to create a layer for each slice you need.  This layer has 2 important characteristics :

  • It's name - which must be "SLICE-xxx" (case insensitive), where xxx is the name of the image file to create, including the extension (.jpg or .png supported)
  • It's size - no matter what is on the layer,oly it's size matter

For each of these "SLICE-*" layer, the image will be flatten (without the "SLICE-*" layers themselves), cropped to the layer's size and saved in the directory specified in the requested parameters.  For .jpg images, the compression quality is requested in the parameters.

This script is my first scheme script, and has to be considered beta quality at most...

 

Version 0.2 :

Corrected the bug when one layer name was < 6 characters

 

Version 0.3 :

Now keep the transparency when saving to .png.  Be carefull, if you have transparent parts in a .jpg slice, as this format does'nt support alpha channel, it will be replaced b something else (black ?).

The modification is quite untested, I hope I have'nt broke something else...   Don't hesitate to mail me !

AttachmentSize
layers-slices.scm v0.15.89 KB
layers-slices.scm v0.26.01 KB
layers-slices.scm v0.36.7 KB

Comments

v3

PNG transparency works as expected. And transparency on JPEGs turn black indeed.

Very nice job, thanks a lot!

This looks really nice

Thank you for your work.

Slice plugin problem

Where i paste this plugin

Good plugin!

I like the plugin a lot. Except that it doesn't generate a html file with the table.. Any easy way to do this? Because I don't like rewriting it myself everytime I change the layout..

Compared to other plugins,

Compared to other plugins, this one does'nt require slices to be next to each other or to completely fill the image.  They can even overlap each other...

In this context, you can't create an HTML table...

HTML file

Well no, a table might be impossible. But who still uses tables to make layouts nowadays? If you do, you seriously should consider going more professional. A table is for showing data, not for layouts. Use for instance DIV tags to build your layout with a CSS stylesheet. Much easier and more reliable.

Anyway, what I wanted to say is... an HTML and CSS file with the image on the right position using DIV tags and stylesheets IS possible. THAT would be awesome!! Since I now have to move them manually to the right places.

trouble with runnin plugin

Hi I cant find where to change the format (png/jpeg) and 2 errors come up; "Plug-In '(null)' left image undo in inconsistent state, closing open undo groups." and "Error: substring: end out of bounds: 6 " are you familiar with this and can someone help me?

I have the same problems,

I have the same problems, gimp 2.6.6 i686 version, Win XP 64-bit

Length of all layer's names

Length of all layer's names must be greater than 6

Finally corrected in v0.2...

Finally corrected in v0.2...

Please add example. Can you

Please add example. Can you please provide us with an example as it is generating errors when I use the following kayer names: SLICE-win.jpg SLICE-tab.jpg SLICE-bgk.jpg Don't understand where to add the size and how to formulate it. Following errors appeared: "Gimp message: Plug-In 'layers-slices' left image undo in inconsistent state, closing open undo groups" and "Error while executing script-fu-layers-slices: Error: Procedure execution of gimp-image-flatten failed".

Great plugin! After looking

Great plugin! After looking at the code I got the clue! The slicing dimensions are determined by the size of the layer :D As mentioned by the author naming of the layer is important. cheers!

That's true, it's the size

That's true, it's the size of the layer.

I choose that because it has to be square, the displayed limit are between pixels and it's easy to handle (via the layer crop tool)

Syndicate content