Cropping a blob image (with problems)

178 views
Skip to first unread message

Christian Koch

unread,
Aug 28, 2011, 4:46:05 AM8/28/11
to play-framework
Hi, in our current project we have to resize an to crop some images
stored in the database. it looks like


try {
File fileOut = File.createTempFile("tmp", ".image");
File fileIn = image.original.getFile();
Images.crop(fileIn, fileOut,
(int)((double)x1*baseFactor),
(int)((double)y1*baseFactor),
(int)((double)x2*baseFactor),
(int)((double)y2*baseFactor)
);
image.image.set(new FileInputStream(fileOut),
MimeTypes.getContentType(image.fileName));
image.save();
renderJSON("{success: true}");
} catch (IOException e) {
e.printStackTrace();
renderJSON("{success: false}");
}

and I get the following exception.

Caused by: javax.imageio.IIOException: Can't read input file!
at javax.imageio.ImageIO.read(ImageIO.java:1275)
at play.libs.Images.crop(Images.java:104)

Can anybody tell me my fault. I don't find it.

Thanks,
Christian

Gaëtan Renaudeau

unread,
Aug 29, 2011, 5:43:09 AM8/29/11
to play-fr...@googlegroups.com
2011/8/28 Christian Koch <christi...@scandio.de>
Hi, in our current project we have to resize an to crop some images
stored in the database.



Images are stored in the database?
So what File fileIn = image.original.getFile(); does?
Make sure you have a real file referenced, else create a temporary file and copy content into to make Images.resize work.



 
it looks like


               try {
                       File fileOut = File.createTempFile("tmp", ".image");
                       File fileIn = image.original.getFile();
                       Images.crop(fileIn, fileOut,
                               (int)((double)x1*baseFactor),
                               (int)((double)y1*baseFactor),
                               (int)((double)x2*baseFactor),
                               (int)((double)y2*baseFactor)
               );
               image.image.set(new FileInputStream(fileOut),
MimeTypes.getContentType(image.fileName));
               image.save();
               renderJSON("{success: true}");
               } catch (IOException e) {
                       e.printStackTrace();
               renderJSON("{success: false}");
               }

and I get the following exception.

       Caused by: javax.imageio.IIOException: Can't read input file!
       at javax.imageio.ImageIO.read(ImageIO.java:1275)
       at play.libs.Images.crop(Images.java:104)

Can anybody tell me my fault. I don't find it.

Thanks,
Christian

--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To post to this group, send email to play-fr...@googlegroups.com.
To unsubscribe from this group, send email to play-framewor...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/play-framework?hl=en.




--
---------------------------------------------------
blog: http://blog.greweb.fr - twitter: http://twitter.com/greweb
<grena...@gmail.com>

Christian Koch

unread,
Aug 29, 2011, 9:07:13 AM8/29/11
to play-framework
Thank you,

Is there any helper method which makes Blob2File easy?

Christian

On 29 Aug., 11:43, Gaëtan Renaudeau <renaudeau.gae...@gmail.com>
wrote:
> 2011/8/28 Christian Koch <christian.k...@scandio.de>
> <grenaud...@gmail.com>

Gaëtan Renaudeau

unread,
Aug 29, 2011, 11:01:23 AM8/29/11
to play-fr...@googlegroups.com
What is the type of your image.original variable?

2011/8/29 Christian Koch <christi...@scandio.de>



--
---------------------------------------------------
http://twitter.com/greweb - http://blog.greweb.fr - http://gaetanrenaudeau.fr

Reply all
Reply to author
Forward
0 new messages