Hi All, I have an issue with the following code which I ain't able to trace. The code is for uploading images, generating the thumbnails ,watermarking the image and saving the watermarked thumbnail to a path on the system. While this is working fine on windows system, it *fails *miserably on linux system. On debian system it does not save the file name as the record name and it saves it with an incremental valued name.
For example if the thumbnail should be 114.thumbnail.jpg on the system it saves as 91.thumbnail.jpg or such name. Note that there is a gap in naming for example there are a few files with names 88.thumbnail.jpg then 90.thumbnail.jpg .. and then 112.thumbnail.jpg. Basically the records ID value appended with .thumbnail.jpg. When a new image is uploaded it should ideally start from 115.thumbnail.jpg as that is the value that is generated and saved in the database. but it takes other value instead when saving the file on the disk may be (if 90.thumnail.. exists already) it will save it as 91.thumbnail.jpg CODE BELOW - if form.accepts(request.vars,session): recordsID= form.vars.id import platform is_windows=(platform.system().lower().find("win") > -1) is_linux=(platform.system().lower().find("lin") > -1) is_mac=(platform.system().lower().find("mac") > -1) if (is_windows == True): #print "is windows" foto_path = (request.folder + "static\\user_uploads\\" + upload_pic) infile = foto_path thumbnail_filename = ("%s" % recordsID + ".thumbnail.jpg") outfile = (request.folder + "static\\thumbs\\" + thumbnail_filename ) thumbpath = os.path.join(request.folder, 'static', 'thumbs\\') + thumbnail_filename elif (is_linux == True): #print "is linux" foto_path = (request.folder + "static/user_uploads/" + upload_pic) infile = foto_path thumbnail_filename = ("%s" % recordsID + ".thumbnail.jpg") #outfile = (request.folder + "static/thumbs/" + thumbnail_filename ) thumbpath = os.path.join(request.folder, 'static', 'thumbs/') + thumbnail_filename outfile = (thumbpath) ## Changed on AUG 25 db(db.fotoz.id==recordsID).update(imgthumb=thumbnail_filename, imgthumbpath=thumbpath) ##outfile if infile != outfile: try: im = Image.open(infile) im.thumbnail(size) #Check for image format image_format = (im.format) #print ("Image format: ", image_format) ### ================ Watermark stuff ====================== width, height = im.size draw = ImageDraw.Draw(im) watermark_text = "WATERMARK" watermark_font = ImageFont.truetype('arial.ttf', 20) textwidth, textheight = draw.textsize(watermark_text, watermark_font) # calculate the x,y coordinates of the text margin = 5 x = width - textwidth - margin y = height - textheight - margin # draw watermark in the bottom right corner ## Specify this to fill font with red color , fill=(128,0,0,128)) OR #, fill=shadowcolor) OR fill="red" or fill="#ff0000" -- work draw.text((x, y), watermark_text, font=watermark_font, opacity=0.25) ## --- Watermark text ends --- #Process various image formats for making thumbnails. Currently supporting JPG/JPEG, GIF and PNG if (image_format == "JPEG"): im.save(outfile, "JPEG") if (image_format == "GIF"): im.save(outfile, "GIF") if (image_format == "PNG"): im.save(outfile, "PNG") except IOError: print("Cannot create thumbnail (un-recognized format) for ", infile) pass If any one has any idea please suggest - Regards, Rahul -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/web2py/6e7eb787-8a70-44e9-9e14-e0c87ace57e8%40googlegroups.com.