Subversion Repositories Scribus

Rev

Rev 13363 | Rev 18122 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
13363 cbradney 1
#!/usr/bin/env python
2
# -*- coding: utf-8 -*-
3
 
4
"""
5
 
6
Diese Skript importiert ein Bild und setzt es auf die akutelle Seite.
7
Der Bildrahmen wird dem Bild angepasst und in den nicht-proportionalen Modus
8
gesetzt, das heisst, beliebige Verzerrungen sind moeglich.
9
 
10
Um das Bild proportional zu vergroessern, die STRG-Taste beim Bearbeiten druecken.
11
 
12
Tested with scribus 1.3.3.3
13
 
14
Author: Konrad Stania
15
 
16
some modifications 2009 by Gregory Pittman, tested on Scribus 1.3.3.13svn
17
 
18
This newer version uses the Python Imaging Library to get the dimensions of the
19
image to be imported, and adjusts the frame accordingly. Initially the frame will
20
be created centered, at 80% of the page's width or height, whichever is smaller.
21
There is an adjustment to 80% of the height of the page in case this is exceeded
22
by the initial calculation.
23
 
24
USAGE:
25
 
26
You must have a document open. Run the script, a dialog asks you to choose an
27
image to load. A proportional frame is automatically created and image loaded,
28
then adjusted to frame size.
29
 
30
LICENSE:
31
 
32
This program is free software; you can redistribute it and/or modify
33
it under the terms of the GNU General Public License as published by
34
the Free Software Foundation; either version 2 of the License, or
35
(at your option) any later version.
36
 
37
This program is distributed in the hope that it will be useful,
38
but WITHOUT ANY WARRANTY; without even the implied warranty of
39
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
40
GNU General Public License for more details.
41
name
42
You should have received a copy of the GNU General Public License
43
along with this program; if not, write to the Free Software
44
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
45
"""
46
 
47
# Craig Bradney, Scribus Team
48
# 10/3/08: Added to Scribus 1.3.3.12svn distribution "as was" from Scribus wiki for bug #6826, script is GPLd
49
 
50
import sys
51
 
52
 
53
try:
54
    from scribus import *
55
 
56
except ImportError:
57
    print "This script only runs from within Scribus."
58
    sys.exit(1)
59
try:
60
    from PIL import Image
61
except ImportError:
62
    print "Unable to import the Python Imaging Library module."
63
    sys.exit(1)
64
 
65
def main():
66
 
67
    pageX,pageY = getPageSize()
68
    ImageFileName = fileDialog("Image Import", "*","" ,True, False)
69
    im = Image.open(ImageFileName)
70
    xsize, ysize = im.size
71
 
72
    if (pageX < pageY):
73
        Breite = pageX * 0.8
74
    else:
75
        Breite = pageY * 0.8
76
    Hoehe = Breite * ysize/xsize
77
 
78
# for images taller than they are wide we want to limit height of frame to 80% of page height
79
    if (Hoehe > pageY * 0.8):
80
        Hoehe = pageY * 0.8
81
        Breite = Hoehe * xsize/ysize
82
 
83
    ImageFrame = createImage(pageX/2 - Breite/2, pageY/2 - Hoehe/2, Breite, Hoehe)
84
    loadImage(ImageFileName, ImageFrame)
85
    setScaleImageToFrame(True, False,ImageFrame)
86
    setFillColor("None", ImageFrame)
87
    setLineColor("None", ImageFrame)
88
 
89
 
90
if __name__ == '__main__':
17396 fschmid 91
    if haveDoc() > 0:
13363 cbradney 92
        main()
93
    else:
94
        messageBox("Image Import", "You need to have a document open <i>before</i> you can run this script succesfully.", ICON_INFORMATION)