| Server IP : 93.86.61.54 / Your IP : 216.73.216.60 Web Server : Apache/2.4.62 (Ubuntu) System : Linux rasin.ddns.net 6.8.0-124-generic #124~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Tue May 26 21:05:19 UTC x86_64 User : www-data ( 33) PHP Version : 8.4.22 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /usr/share/inkscape/extensions/__pycache__/ |
Upload File : |
o
5�a� � @ sT d Z ddlZddlZddlZddlmZ G dd� dej�Zedkr(e� � � dS dS )a�
A script that slices images. It might be useful for web design.
You pass it the name of a layer containing rectangles that cover
the areas that you want exported (the default name for this layer
is "slices"). It then sets the opacity to 0 for all the rectangles
defined in that layer and exports as png whatever they covered.
The output filenames are based on the "Id" field of "Object Properties"
right click contextual menu of the rectangles.
One side effect is that after exporting, it sets the slice rectangles
to different colors with a 25% opacity. (If you want to hide them,
just click on the eye next to the layer).
* red - overwrote a file
* green - wrote a new file
* grey - skipped (not overwriting)
For good pixel exports set the Document Properties, default units to "px"
and the width/height to the real size. (I use 1024x768)
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").
� N)�inkscapec sh e Zd ZdZdZdZdZ� fdd�Zdd� Zd d
� Z dd� Z
d
d� Zdd� Zddd�Z
ddd�Z� ZS )�ExportSlicesz+Exports all rectangles in the current layerz#00ff00z#555555z#ff0000c s t t| ��� i | _d S )N)�superr �__init__� color_map)�self�� __class__� �+/usr/share/inkscape/extensions/layer2png.pyr @ s
zExportSlices.__init__c C sz |� d� |j dtj�d�dd� |j dddd� |j d tjd
d� |j dd
dd� |j dtjdd� |j dddd� d S )Nz--tabz--directory�~zExisting destination directory)�default�helpz--layer�sliceszLayer with slices (rects) in itz
--iconmodezIcon export mode)�typer z--sizesz128, 64, 48, 32, 24, 16zsizes to export comma separatedz--overwritezOverwrite existing exports?z--dpi�300zDots per inch (300 default))�add_argument�os�path�
expanduser�inkex�Boolean)r �parsr
r
r �
add_argumentsE s
��zExportSlices.add_argumentsc C s t j�| jj�st �| jj� | �| jj�}|d u r$t� d�
| jj���|D ]}| �|� q&t�
d�\}}t|d��}|�| j�� � W d � n1 sMw Y |D ])}| jjrx| jj�d�D ]}|�� }|�� rvt|�}| �|||� qaqT| �|� qT|D ]}| �|� q�| jS )NzSlice: '{}' does not exist.z.svg�wb�,)r r �isdir�options� directory�makedirs�get_layer_nodes�layerr �AbortExtension�format�clear_color�tempfile�mkstemp�open�write�svg�tostring�iconmode�sizes�split�strip�isdigit�int�export_node�change_color�document)r �nodes�node�_�tmp_svg�fout�size�png_sizer
r
r �effectP s0 ���zExportSlices.effectc C sB d}| j �d�}|D ]}|j}||kr|}q
|dur|�d�S |S )z�
given the name of a layer one that contains the rectangles defining slices,
return the nodes of the rectangles.
Nzsvg:gzsvg:rect)r) �findall�label)r �
layer_name�
slice_node�slice_layerr5 �label_valuer
r
r r t s �
zExportSlices.get_layer_nodesc C s |j �ddd�� dS )a
set opacity to zero, and stroke to none
Node looks like this:
<rect
style="opacity:0;fill:#eeeeec;fill-opacity:1;stroke:none;stroke-width:4.00099993;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;display:inline"
�none�0)�stroke�opacityN)�style�update)r r5 r
r
r r$ � s zExportSlices.clear_colorc C s* |j d }| j| }|j�|dd�� dS )zJ
set color from color_map and set opacity to 25%
�idz.25)�fillrE N)�attribr rF rG )r r5 �node_id�colorr
r
r r2 � s
zExportSlices.change_colorNc C sP | � |||�\}}|jd }|| j|<