/[theodore]/bunnyblog/gallery.cgi


UCC Code Repository

Contents of /bunnyblog/gallery.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (hide annotations) (download)
Tue Jan 29 14:32:01 2008 UTC (12 years, 2 months ago) by svn-admin
File size: 6468 byte(s)
Re-import of repository after repository database corruption.

1 svn-admin 1 #!/usr/bin/python
2     import cgi
3     import cgitb; cgitb.enable()
4     import blog
5     import os
6     os.sys.path.insert(0,'./modules')
7     from PIL import Image
8     del os.sys.path[0]
9    
10     """
11     BunnyBlog - Image Gallery
12     _________________________
13    
14     This file generates all the views for the image gallery and the image manager.
15     _________________________
16     """
17    
18     """
19     Here we set up all the variables for generating the page
20     """
21     main = ""
22     title = "<@site_name@> - "
23     header = "Hoverbox Image Gallery"
24     meta = """
25     <link rel="stylesheet" href='css/hoverbox.css' type="text/css" media="screen, projection" />
26     <!--[if IE]>
27     <link rel="stylesheet" href='css/ie_fixes.css' type="text/css" media="screen, projection" />
28     <![endif]-->
29     """
30    
31     uploaddir = "data/images/"
32     thumbsdir = "data/images/thumbs/"
33    
34     """
35     Here we retrieve the blog and any arguments
36     Defaults are assigned here
37     """
38     form = cgi.FieldStorage()
39     myblog = blog.Blog()
40     httpstatuscode = "200"
41    
42     def massconvert():
43     for file in os.listdir("./data/images/"):
44     ext = file[-4:]
45     if ext != '.jpg' and ext != ".gif" and ext != ".png": #Skip nonimage files
46     continue
47    
48     size = 256,256
49     im = Image.open(uploaddir+file).save(thumbsdir+file)
50    
51     im = Image.open(thumbsdir+file)
52     im.thumbnail(size)
53     im.save(thumbsdir+file)
54    
55     def imagelist():
56     list = ""
57     for file in os.listdir("./data/images/thumbs/"):
58     ext = file[-4:]
59     if ext != '.jpg' and ext != ".gif" and ext != ".png": #Skip nonimage files
60     continue
61     list += '<li><a href="gallery.cgi?image=%s"><img src="data/images/thumbs/%s" alt="description" /><div class="image_container"><img src="data/images/thumbs/%s" alt="description" class="preview" /></div></a></li>' % (file,file, file)
62     return list
63    
64     def showgallery():
65     return """
66     <h2>Click any of these pictures to see the full image, along with its comments.</h2>
67     <ul class="hoverbox">
68     %s
69     </ul>
70     <p id="hoverbox_footer"><a href="http://validator.w3.org/check/referer">XHTML</a> <a href="http://jigsaw.w3.org/css-validator/check/referer">CSS</a> <a href="http://www.contentquality.com/
71     mynewtester/cynthia.exe?Url1=http://host.sonspring.com/hoverbox/">508</a> | Hoverbox by <a href="http://sonspring.com/">Nathan Smith</a>. | Read the <a href="http://sonspring.com/
72     journal/hoverbox-image-gallery">Tutorial</a>.</p>
73     """ % imagelist()
74    
75    
76     if form.has_key('image'):
77     image = form['image'].value
78     if image == "gallery":
79     main = showgallery()
80     title = "<@site_name@> - Image Gallery"
81     elif image == "upload":
82     if blog.isadmin():
83     main = blog.gettemplate("blog/img_upload")
84     else:
85     main = "Please login before trying to upload images"
86     elif image == "massconv":
87     if blog.isadmin():
88     massconvert()
89     else:
90     main = "Please login before trying to upload images"
91     else:
92     if os.path.exists("./data/images/"+image):
93     if blog.isadmin():
94     admin = '<span style="float:right"><a href="<@site_url@>gallery.cgi?delete=%s">Delete this picture</a></span>' % image
95     else:
96     admin = ""
97     main += '%s<div style="text-align:center;overflow:auto;"><h2>%s</h2><br /><hr /><img src="data/images/%s" alt="description" /></div>' % (admin,image,image)
98     title = "<@site_name@> - Viewing %s" % image
99     header = "<@site_name@> - %s" % image
100     else:
101     main = blog.error(blog.cleanse("File - %s does not exist" % image))
102     header = "<@site_name@> - ERROR finding image"
103     title = header
104     elif form.has_key('upload'):
105     if blog.isadmin():
106     file = form['upload'].file
107     filename = form['upload'].filename
108     ext = filename[-4:]
109     if ext != '.jpg' and ext != ".gif" and ext != ".png": #Skip nonimage files
110     main += blog.error('Upload failed - Disallowed filetype, %s . %s'%(filename,ext))
111     elif os.path.exists("./data/images/"+filename):
112     main = blog.error('Upload failed - File already uploaded')
113     else:
114     f = open(uploaddir+filename,"wb")
115     while 1:
116     chunk = file.read(100000)
117     if not chunk: break
118     f.write (chunk)
119     f.close()
120    
121     size = 256,256
122     im = Image.open(uploaddir+filename).save(thumbsdir+filename)
123    
124     im = Image.open(thumbsdir+filename)
125     pic_x, pic_y = im.size
126    
127     if pic_x/pic_y > 1.5:
128     im = im.crop((.2*pic_x,0,.8*pic_x,pic_y))
129     elif pic_x/pic_y > 2.5:
130     im = im.crop((.3*pic_x,0,.7*pic_x,pic_y))
131     elif pic_x/pic_y > 1.5:
132     im = im.crop((0,.2*pic_y,pic_x,.8*pic_y))
133     elif pic_x/pic_y > 2.5:
134     im = im.crop((0,.3*pic_y,pic_x,.7*pic_y))
135    
136     im.thumbnail(size)
137    
138     im.save(thumbsdir+filename)
139    
140     main = """
141     Upload of %s successful
142    
143     Here is the thumbnail of the image:<br />
144    
145     <div style="text-align:center;overflow:auto;">
146     <img src = "<@site_url@>data/images/thumbs/%s" />
147     </div>
148     <br />
149     Here is the original image: <br />
150    
151     <div style="text-align:center;overflow:auto;">
152     <img src = "<@site_url@>data/images/%s" />
153     </div>
154     """ % (filename, filename, filename)
155     else:
156     main = "Please login before trying to upload images"
157     elif form.has_key('delete'):
158     image = form['delete'].value
159     try:
160     os.remove(uploaddir+image)
161     main += "File: " + uploaddir+image + " successfully deleted<br />"
162     except:
163     main += blog.error("Error: " + uploaddir+image + " was not able to be deleted. This file make have protected permissions, or no longer exists.<br />")
164     try:
165     os.remove(thumbsdir+image)
166     main += "File: " + thumbsdir+image + " successfully deleted<br />"
167     except:
168     main += blog.error("Error: " + thumbsdir+image + " was not able to be deleted. This file make have protected permissions, or no longer exists.<br />")
169     else:
170     main = showgallery()
171     title = "<@site_name@> - Image Gallery"
172    
173    
174     sidebar = blog.gettemplate("blog/shoutbox")
175     if blog.isadmin():
176     sidebar += "<hr />" + blog.gettemplate("admin/toolbar")
177     myblog.display(title,header,main,"blog/mainmenu", sidebar, meta)

Properties

Name Value
svn:executable

Managed by UCC Webmasters ViewVC Help
Powered by ViewVC 1.1.26