Hi,
its driving me nuts. I used the code from web2pyslices to generate 
thumbnails:
db.py:
db.define_table('Images',
    Field('Name',length=512),
    Field('Image','upload'),
    Field('thumb','upload',writable=False,readable=False),
    format = '%(Name)s' # <<< important
    )
db.define_table('Article',
    Field('Title',length=512),
    Field('Content','text'),
    Field('Submitted','datetime',default=datetime.datetime.now()),
    Field('Views','integer',default=0),
    Field('TopImage',db.Images)
    )
default.py:
def download():
    return response.download(request, db)
def makeThumbnail(dbtable,ImageID,size=(200,200)):
    try:
        thisImage=db(dbtable.id==ImageID).select()[0]
        import os, uuid
    except: 
        print "Error while loading libraries"
        return
    try:
        from PIL import Image
    except:
        print "Error while Importing PIL library"
        return
    print request.folder + 'uploads/' + thisImage.Image
    im=Image.open(request.folder + 'uploads/' + thisImage.Image)
    im.thumbnail(size,Image.ANTIALIAS)
    thumbName='uploads.thumb.%s.jpg' % (uuid.uuid4())
    im.save(request.folder + 'uploads/' + thumbName,'jpeg')
    thisImage.update_record(thumb=thumbName)
    response.flash = 'Thumb created everything went fine'
    return
def newImage():
    dbtable = db.Images          #uploads table name
    if len(request.args):
        records = db(dbtable.id==request.args[0]).select()
    if len(request.args) and len(records):
        form = SQLFORM(dbtable, records[0], deletable=True)
    else:
        form = SQLFORM(dbtable)
    if form.accepts(request.vars, session):
        response.flash = 'Entry for Images Database accepted,start creating 
thumb'
        makeThumbnail(dbtable,form.vars.id,(200,200))
    elif form.errors:
        response.flash = 'Error in Form for Images Database'
    ## Quick list just to demonstrate...
    list = crud.select(dbtable)
    return dict(form=form,list=list)
def Article():
    id=request.vars.id
    row=db(db.Article.id==id).select()
    row[0].update_record(Views=row[0].Views+1)
    if len(row)==0:
        redirect(URL(r=request,f='Articles'))
    return dict(Article=row[0])
article.html
{{extend 'layout.html'}}
<h1> {{=Article.Title}} </h1>
<br>
<center>
{{print URL(r=request, c='default', 
f='download',args=Article.TopImage.thumb)}}
{{=IMG(_src=URL(r=request, c='default', 
f='download',args=Article.TopImage.thumb),_style="display:block;")}}
 </center>
 <br>
{{=XML(Article.Content)}}<br><br>
the thumbnail is generated by the code as it should. and it lands in the 
upload folder with the original image as it should. if I change the 
article.TopImage.thumb to .image it works perfectly. if I change it to 
.thumb again no image is displayed. the path and name I get from the print 
seem to be correct at least it is the same path as for the origianl image.
thanks for your help guys

-- 



Reply via email to