[web2py] Can't retrieve xy.jpeg file properties (.thumbnail vs .jpeg) from PIL resized image (2.6.0-dev)

2013-08-27 Thread Adi

Used the Python Imaging Library (with JPEG decoder) to create set of 
thumbnails. For the images with jpeg extension, the error pops up that the 
properties can't be retrieved, while for the non-image extensions, 
everything displays fine. 

Is this a problem with PIL not generating enough header information about 
the image, or something else? Size-wise, .thumbnail is 4x smaller, but the 
quality is really low. The original JPG displays fine too... 

thumbnails resizing: 
...
im = Image.open(infile)
im.thumbnail(size)
im.save(outfile, JPEG)



displaying images:
{{
img1 = 
'product.image.85d32040405f61e9.626c61636b2d6e616d6d752e6a7067.thumbnail180x160'
img2 = 
'product.image.85d32040405f61e9.626c61636b2d6e616d6d752e6a7067.180x160.jpeg'
}}

!--img src={{#=URL('download', args=img1, scheme=True, host=True)}}--
img src={{=URL('download', args=img2, scheme=True, host=True)}}



Traceback (most recent call last):
 
 File /Users/adnan/web2py26/gluon/restricted.py, line 217, in restricted
exec ccode in environment
  File /Users/adnan/web2py26/applications/nammu/controllers/default.py,line 
2983, in module

  File /Users/adnan/web2py26/gluon/globals.py, line 361, in lambda
self._caller = lambda f: f()
  File /Users/adnan/web2py26/applications/nammu/controllers/default.py,line 
2105, in download
return response.download(request, db)
  File /Users/adnan/web2py26/gluon/globals.py, line 574, in download
(filename, stream) = field.retrieve(name,nameonly=True)
  File /Users/adnan/web2py26/gluon/dal.py, line 9558, in retrieve
file_properties = self.retrieve_file_properties(name,path)
  File /Users/adnan/web2py26/gluon/dal.py, line 9583, 
inretrieve_file_properties
raise TypeError('Can\'t retrieve %s file properties' % name)
TypeError: Can't retrieve 
product.image.85d32040405f61e9.626c61636b2d6e616d6d752e6a7067.180x160.jpeg 
file properties




-- 

--- 
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.
For more options, visit https://groups.google.com/groups/opt_out.


product.image.85d32040405f61e9.626c61636b2d6e616d6d752e6a7067.thumbnail180x160
Description: Binary data
attachment: product.image.85d32040405f61e9.626c61636b2d6e616d6d752e6a7067.180x160.jpeg

Re: [web2py] Can't retrieve xy.jpeg file properties (.thumbnail vs .jpeg) from PIL resized image (2.6.0-dev)

2013-08-27 Thread Ricardo Pedroso
On Tue, Aug 27, 2013 at 5:22 PM, Adi adnan.smajlo...@gmail.com wrote:


 Used the Python Imaging Library (with JPEG decoder) to create set of
 thumbnails. For the images with jpeg extension, the error pops up that the
 properties can't be retrieved, while for the non-image extensions,
 everything displays fine.




 Traceback (most recent call last):

  File /Users/adnan/web2py26/gluon/restricted.py, line 217, in restricted
 exec ccode in environment
   File /Users/adnan/web2py26/applications/nammu/controllers/default.py,line
 2983, in module

   File /Users/adnan/web2py26/gluon/globals.py, line 361, in lambda
 self._caller = lambda f: f()
   File /Users/adnan/web2py26/applications/nammu/controllers/default.py,line
 2105, in download
 return response.download(request, db)
   File /Users/adnan/web2py26/gluon/globals.py, line 574, in download
 (filename, stream) = field.retrieve(name,nameonly=True)
   File /Users/adnan/web2py26/gluon/dal.py, line 9558, in retrieve
 file_properties = self.retrieve_file_properties(name,path)
   File /Users/adnan/web2py26/gluon/dal.py, line 9583, 
 inretrieve_file_properties
 raise TypeError('Can\'t retrieve %s file properties' % name)
 TypeError: Can't retrieve
 product.image.85d32040405f61e9.626c61636b2d6e616d6d752e6a7067.180x160.jpeg
 file properties



It's a filename regex issue.
The regex above (REGEX_UPLOAD_PATTERN) is what is used in dal.py


import re

# this is ok. Has a _180x160 instead of .180x160
name =
'product.image.85d32040405f61e9.626c61636b2d6e616d6d752e6a7067_180x160.jpeg'

# this one fails
name =
'product.image.85d32040405f61e9.626c61636b2d6e616d6d752e6a7067.180x160.jpeg'

REGEX_UPLOAD_PATTERN =
re.compile('(?Ptable[\w\-]+)\.(?Pfield[\w\-]+)\.(?Puuidkey[\w\-]+)(\.(?Pname\w+))?\.\w+$')

m = REGEX_UPLOAD_PATTERN.match(name)
assert(m is not None)
print m.groupdict()

-- 

--- 
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.
For more options, visit https://groups.google.com/groups/opt_out.