Hi. I run a website for my band, and the other guys want an image gallery.
I'm thinking it would be nice and easy, if we could just upload a jpg into
a dir called "gallery/". When the client clicks the "gallery" link, a
cgi script could search the gallery/ dir, and create thumbnails of any
jpeg images that don't already have a thumbnail associated with them. The
script could then generate a page of clickable thumbnails.
A few questions:
(1) Can this be done with python? If so, what module do I need to look up?
(2) If it can't be done with python, is there some small utility that will
do it for me? Something I could easily install locally in my own
"public_htm l" dir on my website?
(3) Is this the sort of thing which, if done regularly, would hog far far
too much of my webhosts system resources?
(4) Am I talking about re inventing the wheel? 8 4815
"Chris Dewin" <ch***@wintergr een.in> writes: (1) Can this be done with python? If so, what module do I need to look up?
You could do it with PIL, or run jpegtran in an external process.
jpegtran may be easier.
Chris Dewin wrote: Hi. I run a website for my band, and the other guys want an image gallery.
I'm thinking it would be nice and easy, if we could just upload a jpg into a dir called "gallery/". When the client clicks the "gallery" link, a cgi script could search the gallery/ dir, and create thumbnails of any jpeg images that don't already have a thumbnail associated with them. The script could then generate a page of clickable thumbnails.
A few questions:
(1) Can this be done with python? If so, what module do I need to look up?
PIL can certainly handle the functionality.
(2) If it can't be done with python, is there some small utility that will do it for me? Something I could easily install locally in my own "public_html " dir on my website?
The core function looks something like this:
import Image # this is PIL
def getThumbnail( filename, size = (32,32) ):
'''Get a thumbnail image of filename'''
image = Image.open(file name)
rx, ry = image.size[0]/float(size[0]), image.size[1]/float(size[1])
if rx > ry:
resize = int(size[0]), int(round(image .size[1]*(1.0/rx), 0))
else:
resize = int(round(image .size[0]*(1.0/ry), 0)), int(size[1])
image = image.resize( resize, Image.BILINEAR )
newimage = Image.new( 'RGB', size, )
x,y = image.size
newimage.paste(
image, ((size[0]-x)/2, (size[1]-y)/2),
)
return newimage
then you call newImage.save( filename, format ) to save the result.
(3) Is this the sort of thing which, if done regularly, would hog far far too much of my webhosts system resources?
As long as you *only* generate images for sources that don't yet have
(or are newer than) their thumbnail you should be fine.
(4) Am I talking about re inventing the wheel?
Probably. ZPhotoSlides (a Zope product) provides thumnailing,
slideshows and the like, probably closer to what you'd want for this
kind of application. You'll probably find other non-Zope versions as well.
Good luck,
Mike
--
_______________ _______________ _______________ ___
Mike C. Fletcher
Designer, VR Plumber, Coder http://www.vrplumber.com http://blog.vrplumber.com
>I'm thinking it would be nice and easy, if we could just upload a jpg into a dir called "gallery/". When the client clicks the "gallery" link, a cgi script could search the gallery/ dir, and create thumbnails of any jpeg images that don't already have a thumbnail associated with them. The script could then generate a page of clickable thumbnails.
I dunno about the scripting aspect, but I use Python to generate my
website, I already had the images (of the products I sell). I used PIL
to generate thumbnails of the images. I think it took 2 or 3 lines of
Python - that is: for me. PIL is of course a bit more.
Wouter van Ooijen
-- ------------------------------------ http://www.voti.nl
Webshop for PICs and other electronics http://www.voti.nl/hvu
Teacher electronics and informatics
On Saturday 27 August 2005 09:06 pm, Chris Dewin wrote: I'm thinking it would be nice and easy, if we could just upload a jpg into a dir called "gallery/". When the client clicks the "gallery" link, a cgi script could search the gallery/ dir, and create thumbnails of any jpeg images that don't already have a thumbnail associated with them. The script could then generate a page of clickable thumbnails.
This is trivial to do with Zope. I wrote a "VarImage" product for it
that will do the image manipulation you want handily. I never really
created a "gallery" product for it because it's so trivial to do with a
regular Zope folder and a couple of scripts, but I would be happy to
share my Gallery template with you if your interested.
The current version of VarImage even implements things like HTTP_REFERER
blocking (or watermarking if you prefer), to discourage remote-linking
of your images, etc.
An online example can be seen here: http://narya.net/Gallery
Not sure about CGI methods of doing it, though.
--
Terry Hancock ( hancock at anansispacework s.com )
Anansi Spaceworks http://www.anansispaceworks.com
Paul Rubin wrote (1) Can this be done with python? If so, what module do I need to look up?
You could do it with PIL, or run jpegtran in an external process. jpegtran may be easier.
eh? are you sure you know what jpegtran does?
JPEGTRAN(1)
JPEGTRAN(1)
NAME
jpegtran - lossless transformation of JPEG files
SYNOPSIS
jpegtran [ options ] [ filename ]
DESCRIPTION
jpegtran performs various useful transformations of JPEG files. It
can
translate the coded representation from one variant of JPEG to
another,
for example from baseline JPEG to progressive JPEG or vice versa.
It
can also perform some rearrangements of the image data, for
example
turning an image from landscape to portrait format by rotation.
jpegtran works by rearranging the compressed data (DCT
coefficients),
without ever fully decoding the image /.../
</F>
Mike C. Fletcher wrote: The core function looks something like this:
import Image # this is PIL
def getThumbnail( filename, size = (32,32) ): '''Get a thumbnail image of filename''' image = Image.open(file name) rx, ry = image.size[0]/float(size[0]), image.size[1]/float(size[1]) if rx > ry: resize = int(size[0]), int(round(image .size[1]*(1.0/rx), 0)) else: resize = int(round(image .size[0]*(1.0/ry), 0)), int(size[1]) image = image.resize( resize, Image.BILINEAR )
footnote: if you're creating thumbnails from JPEG or PhotoCD
images, using the "thumbnail" method can be a lot more efficient
(unlike resize, it tweaks the codec so it doesn't have to load the
entire full-sized image).
footnote 2: Image.ANTIALIAS is slower, but tends to give a
much better result than Image.BILINEAR, especiall for "noisy"
images.
</F>
"Fredrik Lundh" <fr*****@python ware.com> writes: You could do it with PIL, or run jpegtran in an external process. jpegtran may be easier.
eh? are you sure you know what jpegtran does?
JPEGTRAN(1)
Whoops, sorry, right, jpegtran is for rotating the images. I meant:
use a pipeline like
djpeg -scale 1/4 | cjpeg
That's how I usually do it. Main disadvantage is the scale factor has
to be 1/2, 1/4, 1/8, etc., not arbitrary amounts like 0.3456.
Chris Dewin wrote: Hi. I run a website for my band, and the other guys want an image gallery.
I'm thinking it would be nice and easy, if we could just upload a jpg into a dir called "gallery/". When the client clicks the "gallery" link, a cgi script could search the gallery/ dir, and create thumbnails of any jpeg images that don't already have a thumbnail associated with them. The script could then generate a page of clickable thumbnails.
Once I made an example mod_python handler, that resized images on the fly.
For example: http://server/folder/image.jpg - would give you the original image, served
directly by apache without any performance hit. http://server/folder/image.jpg?thumbnail - would resize the picture (and
cache the result on disk) and return that, on a second request it would
return the cached image very fast by calling an apache.send_fil e function.
see http://www.modpython.org/pipermail/m...er/016471.html
--
damjan This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Chris McKeever |
last post by:
I am trying to modify the Mailman Python code to stop mapping
MIME-types and use the extension of the attachment instead. I am
pretty much clueless as to what I need to do here, but I think I have
narrowed it down to the Scrubber.py file..
If this seems like a quick step me through, I would be very
appreciative, could get you something on your Amazon wish-list (that
is me on my knees begging)..
From just my basic understanding, it...
|
by: Premshree Pillai |
last post by:
Hello people,
I recently updated one of my Python scripts --
pyAlbum.py
This is a simple, command-line based, lightweight
Python script to create an image album.
Of course, there are plenty of image album creation
tools -- a lot of them are very good. But, I wanted
something very simple, something that doesn't scare
|
by: Scott Brady Drummonds |
last post by:
Can anyone recommend the easiest way of generating thumbnail images using a
Python library? I've seen that the Python Image Library (PIL) seems to do
this but it isn't installed on my available systems. I'd prefer to use
something distributed with Python, if possible, but will install the library
that makes this functionality easy as a second choice.
Thanks!
Scott
--
|
by: sepgy |
last post by:
Can anyone help me to use a python to create an HTML photo gallery
generator. When it's finished, it will be able find all the picture
files (i.e. .jpg, .gif. .png files) in any given folder on the
computer, automatically create smaller thumbnails for each image, and
then generate a complete HTML file that displays a clickable image
gallery. When viewed in a web browser, the HTML file will display the
thumbnails in a neatly formatted...
|
by: Blake T. Garretson |
last post by:
I want to save some sensitive data (passwords, PIN numbers, etc.) to
disk in a secure manner in one of my programs. What is the
easiest/best way to accomplish strong file encryption in Python? Any
modern block cipher will do: AES, Blowfish, etc. I'm not looking for
public key stuff; I just want to provide a pass-phrase.
I found a few modules out there, but they seem to be all but abandoned.
Most seem to have died several years ago. ...
| |
by: David W. Simmonds |
last post by:
I have a DataList control that has an Image control in the ItemTemplate. I
would like to resize the image that goes into that control. I have a series
of jpg files that are full size, full resolution (ie. large). I have a
database that contains references to the pictures. Currently I have to
resize the jpgs manually, and then point the ImageUrl property at that jpg
using databinding. This works fine. I would like to avoid the resizing step...
|
by: John Swan |
last post by:
Hello.
I'm trying to create a simple program that amongst other things creates a
thumbnail of an image (Bitmap) to a set size determined by the user in
pixels?
The problem is: All of the examples I have seen so far are in c#.
Can anyone please provide reference to a c++ managed version.
Thanks.
John
|
by: Danny Ni |
last post by:
Hi,
I am looking for a way to display images with different aspect ratio into
frames with fixed width and height, the problem is some images will look
distorted if they are forced into fixed frame due to differnt aspect ratio.
Some graphic designer suggests me to keep the aspect ratio of the original
graphic and pad the graphic with empty space to fit into the frame. One
example, the fixed frame is 100x60 and the image is 120x120, I...
|
by: dodgeyb |
last post by:
Hi there,
Trying to allow client to upload image, thumbnail it, and save it into
sql table image field.
Code compiles & runs but image cannot be retrieved. any clues what I'm
doing wrong pls !
Dim origImage As System.Drawing.Image =
System.Drawing.Image.FromStream(FileUpload1.PostedFile.InputStream)
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |