Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Antti Väyrynen
/
Moya
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit c9b01cc0
authored
May 11, 2013
by
Tuomas Riihimäki
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'devel' of codecrew.fi:bortal into devel
2 parents
94b95dfc
027c6243
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
1 deletions
code/MoyaBeans/ejbModule/fi/codecrew/moya/beans/UserBean.java
code/MoyaWeb/WebContent/user/sendPicture.xhtml
code/MoyaBeans/ejbModule/fi/codecrew/moya/beans/UserBean.java
View file @
c9b01cc
package
fi
.
codecrew
.
moya
.
beans
;
import
java.awt.Graphics2D
;
import
java.awt.RenderingHints
;
import
java.awt.geom.AffineTransform
;
import
java.awt.image.AffineTransformOp
;
import
java.awt.image.BufferedImage
;
import
java.io.ByteArrayInputStream
;
import
java.io.ByteArrayOutputStream
;
...
...
@@ -225,11 +229,59 @@ public class UserBean implements UserBeanLocal {
throw
new
EJBAccessException
(
"No permission to upload image as another user"
);
}
ByteArrayInputStream
imagestream
=
new
ByteArrayInputStream
(
image
);
BufferedImage
bimage
;
try
{
bimage
=
ImageIO
.
read
(
imagestream
);
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
e
);
}
int
maxImageWidth
=
1000
;
int
maxImageHeight
=
1000
;
if
(
bimage
.
getWidth
()
>
maxImageWidth
||
bimage
.
getHeight
()
>
maxImageHeight
)
{
int
w
=
bimage
.
getWidth
();
int
h
=
bimage
.
getHeight
();
if
(
w
>
h
)
{
h
=
(
int
)
(((
double
)
h
/
(
double
)
w
)*
(
double
)
maxImageWidth
);
w
=
maxImageWidth
;
}
else
{
w
=
(
int
)
(((
double
)
w
/
(
double
)
h
)*
(
double
)
maxImageHeight
);
h
=
maxImageHeight
;
}
logger
.
info
(
"scaling image to {} x {}"
,
w
,
h
);
BufferedImage
resized
=
new
BufferedImage
(
w
,
h
,
bimage
.
getType
());
Graphics2D
g
=
resized
.
createGraphics
();
g
.
setRenderingHint
(
RenderingHints
.
KEY_INTERPOLATION
,
RenderingHints
.
VALUE_INTERPOLATION_BILINEAR
);
g
.
drawImage
(
bimage
,
0
,
0
,
w
,
h
,
0
,
0
,
bimage
.
getWidth
(),
bimage
.
getHeight
(),
null
);
g
.
dispose
();
bimage
=
resized
;
}
ByteArrayOutputStream
naamaout
=
new
ByteArrayOutputStream
();
try
{
ImageIO
.
write
(
bimage
,
"png"
,
naamaout
);
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
e
);
}
UserImage
userimage
=
null
;
userimage
=
new
UserImage
(
user
.
getUser
());
userimage
.
setMimeType
(
contentType
);
userimage
.
setImageData
(
image
);
userimage
.
setImageData
(
naamaout
.
toByteArray
()
);
userimage
.
setName
(
filename
);
userimage
.
setDescription
(
description
);
...
...
code/MoyaWeb/WebContent/user/sendPicture.xhtml
View file @
c9b01cc
...
...
@@ -47,6 +47,9 @@
<h2>
#{i18n['user.thisIsCurrentImage']}
</h2>
<h:outputText
rendered=
"#{empty userView.user.currentImage}"
value=
"#{i18n['user.noCurrentImage']}"
/>
<img
width=
"300"
rendered=
"#{!empty userView.user.currentImage}"
src=
"#{request.contextPath}/dydata/userimage/#{userView.user.currentImage.id}.jpg"
alt=
"image"
/>
<!-- <ui:fragment rendered="#{!empty userView.user.currentImage}">
<img width="300" src="#{request.contextPath}/dydata/userimage/#{userView.user.currentImage.id}.img" alt="image" />
<div>
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment