 |
forum.vmspython.org Forum system
|
View previous topic :: View next topic |
Author |
Message |
urs mantel
Joined: 02 Nov 2010 Posts: 16 Location: Switzerland
|
Posted: Mon May 16, 2016 10:04 pm Post subject: PIL image processing error |
|
|
Hello Jean-François,
I recently upgraded from 2.5.4 to 2.7.9
since then processing of JPEG images with PIL is not possible
>>>import PIL, PIL.Image
>>>filename = '1.jpg'
>>>im = PIL.Image.open(filename)
>>>print im.format
JPEG
>>>im.load()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/python_root/local/PIL/ImageFile.py", line 207, in load
raise IOError(error + " when reading image file")
IOError: decoding error when reading image file
with 2.5.4 (May 14 2011) it was ok (with corresponding LIB)
2.7.6, 2.7.9, 2.7.11 are not ok
any hints?
Thanks
Urs |
|
Back to top |
|
 |
jfp
Joined: 12 Jul 2004 Posts: 636
|
Posted: Wed May 18, 2016 6:30 am Post subject: |
|
|
Hello Urs,
be sure that the file has a record format Fixed length or stream lf.
There are some change in Python around thiis, in don't remember exactly in which version.
JF |
|
Back to top |
|
 |
urs mantel
Joined: 02 Nov 2010 Posts: 16 Location: Switzerland
|
Posted: Wed May 18, 2016 10:44 pm Post subject: |
|
|
Hello Jean-François,
excellent remote diagnose !
If the file has RFM:STMLF instead of STM then it will be processed by PIL.
Nevertheless - strange enough the whole processing is made in python
HTML form with input type=file (JPEG) is submitted through WASD PYRTE Python to the script
Code: |
form = cgi.FieldStorage()
fileitem = form["PHOTOFILE"]
...
fout = file(temp_filename, 'wb')
while 1:
chunk = fileitem.file.read(100000)
if not chunk: break
fout.write (chunk)
fout.close()
if format != "JPEG":
do something
im = Image.open(temp_filename)
im.thumbnail(size,mode) <---- raises exeption
im.save(temp_filename_thumbnail)
...
|
Even hundreds of already processed files have RFM:STMLF automatically received from Python (2.5.4) – why not with 2.7.9/11?
Where should I or could I say save as STMLF ?
Urs |
|
Back to top |
|
 |
jfp
Joined: 12 Jul 2004 Posts: 636
|
Posted: Thu May 19, 2016 3:36 pm Post subject: |
|
|
Hello Urs,
The only reason, I can imagine, to have a file with RFM:STM instead of RFM:STMLF is that there is a previous version of the file with the incorrect RFM format.
Python, as it is written in C, always create file using RFM:STMLF.
But if a previous version exist, OpenLMS CRTL create a new version with the same RFM as the previous version.
To be sure to create a correct file format, you can use the file class directly which allow to specified rmsattr instead if the open function.
Code: | $ python -c help(file)
Help on class file in module __builtin__:
class file(object)
| file(name[, mode[, buffering[, rmsattr]]]) -> file object
|
| Open a file. The mode can be 'r', 'w' or 'a' for reading (default),
| writing or appending. The file will be created if it doesn't exist
| when opened for writing or appending; it will be truncated when
| opened for writing. Add a 'b' to the mode for binary files.
| Add a '+' to the mode to allow simultaneous reading and writing.
| If the buffering argument is given, 0 means unbuffered, 1 means line
| buffered, and larger numbers specify the buffer size. The preferred way
| to open a file is with the builtin open() function.
| Add a 'U' to mode to open the file for input with universal newline
| support. Any line ending in the input file will be seen as a '\n'
| in Python. Also, a file so opened gains the attribute 'newlines';
| the value for this attribute is one of None (no newline read yet),
| '\r', '\n', '\r\n' or a tuple containing all the newline types seen.
|
| 'U' cannot be combined with 'w' or '+' mode.
|
| Under OpenVMS you can specify an optional list or tuple of RMS attributes:
| >>> rmsattr = ['ctx=stm','rfm=fix','mrs=512']
| >>> fp = file('XYZ.DAT','w',0,rmsattr)
| See the C RTL manual for a full list of attributes. If rmsattr is not
| specified, or has a value of None, then default attributes will be applied.
| A value of "" forces no attributes.
...
|
JF |
|
Back to top |
|
 |
urs mantel
Joined: 02 Nov 2010 Posts: 16 Location: Switzerland
|
Posted: Sun May 22, 2016 9:18 pm Post subject: |
|
|
Hello Jean-François,
everything is ok with the saved files from HTML form - all files are with RAT:STMLF
(I've got an old file as example with RAT:STM (must have been saved with FTP or Pathworks))
The uploaded files get RAT:STMLF automatically
However, I'm still not able to process the files with PIL.
Are you able to open and load a JPEG file?
Code: |
>>>import PIL.Image
>>>im = PIL.Image.open('filename.jpg')
>>>im.load()
|
Thanks
Urs |
|
Back to top |
|
 |
jfp
Joined: 12 Jul 2004 Posts: 636
|
Posted: Mon May 23, 2016 5:32 pm Post subject: |
|
|
Hello Urs,
Using 2.7.11 I reproduce the problem, seem a GIF file open and load correctly but a JPEG one fail.
May be time to upgrade PIL to latest version...
Or better, as it seem that PIL is dead, to switch to Pillow: https://github.com/python-pillow/Pillow
JF |
|
Back to top |
|
 |
jfp
Joined: 12 Jul 2004 Posts: 636
|
Posted: Thu Nov 17, 2016 11:39 am Post subject: |
|
|
Hello Urs,
I have, probably, found the bug.
It is a regression in the port of libjpeg.
This is fixed, and be provided with Python 2.7.12
JF |
|
Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|