parent
3fb7e5bee3
commit
2140134ebe
3 changed files with 31 additions and 22 deletions
|
@ -105,8 +105,7 @@ class Index extends App.ControllerSubContent
|
||||||
new Camera
|
new Camera
|
||||||
callback: @storeImage
|
callback: @storeImage
|
||||||
|
|
||||||
storeImage: (src) =>
|
storeImage: (src, type) =>
|
||||||
|
|
||||||
# store avatar globally
|
# store avatar globally
|
||||||
@oldDataUrl = src
|
@oldDataUrl = src
|
||||||
|
|
||||||
|
@ -128,16 +127,19 @@ class Index extends App.ControllerSubContent
|
||||||
)
|
)
|
||||||
|
|
||||||
# add resized image
|
# add resized image
|
||||||
App.ImageService.resizeForAvatar(src, 'auto', 160, store)
|
App.ImageService.resizeForAvatar(src, 'auto', 160, type, store)
|
||||||
|
|
||||||
onUpload: (event) =>
|
onUpload: (event) =>
|
||||||
|
file = event.target.files[0]
|
||||||
callback = @storeImage
|
callback = @storeImage
|
||||||
EXIF.getData event.target.files[0], ->
|
|
||||||
|
EXIF.getData file, ->
|
||||||
orientation = @exifdata.Orientation
|
orientation = @exifdata.Orientation
|
||||||
reader = new FileReader()
|
reader = new FileReader()
|
||||||
reader.onload = (e) ->
|
reader.onload = (e) ->
|
||||||
new ImageCropper
|
new ImageCropper
|
||||||
imageSource: e.target.result
|
imageSource: e.target.result
|
||||||
|
type: file.type
|
||||||
callback: callback
|
callback: callback
|
||||||
orientation: orientation
|
orientation: orientation
|
||||||
|
|
||||||
|
@ -182,7 +184,7 @@ class ImageCropper extends App.ControllerModal
|
||||||
@image.attr src: dataUrl
|
@image.attr src: dataUrl
|
||||||
|
|
||||||
# resize if to big
|
# resize if to big
|
||||||
App.ImageService.resize(@imageSource, 600, 'auto', 2, 'image/jpeg', 0.9, show)
|
App.ImageService.resize(@imageSource, 600, 'auto', 2, @type, 0.9, show)
|
||||||
|
|
||||||
orientateImage: (e) =>
|
orientateImage: (e) =>
|
||||||
image = e.currentTarget
|
image = e.currentTarget
|
||||||
|
@ -220,7 +222,7 @@ class ImageCropper extends App.ControllerModal
|
||||||
|
|
||||||
onSubmit: (e) =>
|
onSubmit: (e) =>
|
||||||
@formDisable(e)
|
@formDisable(e)
|
||||||
@callback( @image.cropper('getCroppedCanvas').toDataURL() )
|
@callback( @image.cropper('getCroppedCanvas').toDataURL(), @type )
|
||||||
@image.cropper('destroy')
|
@image.cropper('destroy')
|
||||||
@close()
|
@close()
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
class App.ImageService
|
class App.ImageService
|
||||||
|
@supported_types: ['image/jpeg', 'image/png']
|
||||||
|
|
||||||
@resizeForAvatar: (dataURL, x, y, callback) =>
|
@resizeForAvatar: (dataURL, x, y, type = @supported_types[0], callback) =>
|
||||||
if @checkUrl(dataURL)
|
if @checkUrl(dataURL)
|
||||||
callback(dataURL)
|
callback(dataURL)
|
||||||
else
|
else
|
||||||
@resize(dataURL, x, y, 2, 'image/jpeg', 0.7, callback)
|
@resize(dataURL, x, y, 2, type, 0.7, callback)
|
||||||
|
|
||||||
@resizeForApp: (dataURL, x, y, callback) =>
|
@resizeForApp: (dataURL, x, y, callback) =>
|
||||||
if @checkUrl(dataURL)
|
if @checkUrl(dataURL)
|
||||||
|
@ -12,11 +13,11 @@ class App.ImageService
|
||||||
else
|
else
|
||||||
@resize(dataURL, x, y, 2, 'image/png', 0.7, callback)
|
@resize(dataURL, x, y, 2, 'image/png', 0.7, callback)
|
||||||
|
|
||||||
@resize: (dataURL, x = 'auto', y = 'auto', sizeFactor = 1, type, quallity, callback, force = true) ->
|
@resize: (dataURL, x = 'auto', y = 'auto', sizeFactor = 1, type, quality, callback, force = true) ->
|
||||||
|
|
||||||
# load image from data url
|
# load image from data url
|
||||||
imageObject = new Image()
|
imageObject = new Image()
|
||||||
imageObject.onload = ->
|
imageObject.onload = =>
|
||||||
imageWidth = imageObject.width
|
imageWidth = imageObject.width
|
||||||
imageHeight = imageObject.height
|
imageHeight = imageObject.height
|
||||||
console.log('ImageService', 'current size', imageWidth, imageHeight)
|
console.log('ImageService', 'current size', imageWidth, imageHeight)
|
||||||
|
@ -68,26 +69,26 @@ class App.ImageService
|
||||||
context = canvas.getContext('2d')
|
context = canvas.getContext('2d')
|
||||||
context.drawImage(imageObject, 0, 0, imageWidth, imageHeight)
|
context.drawImage(imageObject, 0, 0, imageWidth, imageHeight)
|
||||||
|
|
||||||
# set quallity based on image size
|
# set quality based on image size
|
||||||
if quallity == 'auto'
|
if quality == 'auto'
|
||||||
if x < 200 && y < 200
|
if x < 200 && y < 200
|
||||||
quallity = 1
|
quality = 1
|
||||||
else if x < 400 && y < 400
|
else if x < 400 && y < 400
|
||||||
quallity = 0.9
|
quality = 0.9
|
||||||
else if x < 600 && y < 600
|
else if x < 600 && y < 600
|
||||||
quallity = 0.8
|
quality = 0.8
|
||||||
else if x < 900 && y < 900
|
else if x < 900 && y < 900
|
||||||
quallity = 0.7
|
quality = 0.7
|
||||||
else
|
else
|
||||||
quallity = 0.6
|
quality = 0.6
|
||||||
|
|
||||||
# execute callback with resized image
|
# execute callback with resized image
|
||||||
newDataUrl = canvas.toDataURL(type, quallity)
|
newDataUrl = canvas.toDataURL(@validateType(type), quality)
|
||||||
if resize
|
if resize
|
||||||
console.log('ImageService', 'resize', x/sizeFactor, y/sizeFactor, quallity, (newDataUrl.length * 0.75)/1024/1024, 'in mb')
|
console.log('ImageService', 'resize', x/sizeFactor, y/sizeFactor, quality, (newDataUrl.length * 0.75)/1024/1024, 'in mb')
|
||||||
callback(newDataUrl, x/sizeFactor, y/sizeFactor, true)
|
callback(newDataUrl, x/sizeFactor, y/sizeFactor, true)
|
||||||
return
|
return
|
||||||
console.log('ImageService', 'no resize', x, y, quallity, (newDataUrl.length * 0.75)/1024/1024, 'in mb')
|
console.log('ImageService', 'no resize', x, y, quality, (newDataUrl.length * 0.75)/1024/1024, 'in mb')
|
||||||
callback(newDataUrl, x, y, false)
|
callback(newDataUrl, x, y, false)
|
||||||
|
|
||||||
# load image from data url
|
# load image from data url
|
||||||
|
@ -96,3 +97,11 @@ class App.ImageService
|
||||||
@checkUrl: (dataURL) ->
|
@checkUrl: (dataURL) ->
|
||||||
ignore = /\.svg$/i
|
ignore = /\.svg$/i
|
||||||
ignore.test(dataURL)
|
ignore.test(dataURL)
|
||||||
|
|
||||||
|
# check if the image type is supported
|
||||||
|
# otherwise return our standard image type (the first listed supported type)
|
||||||
|
@validateType: (type) =>
|
||||||
|
if @supported_types.indexOf(type) == -1
|
||||||
|
return @supported_types[0]
|
||||||
|
else
|
||||||
|
return type
|
||||||
|
|
|
@ -3786,7 +3786,6 @@ footer {
|
||||||
height: 40px;
|
height: 40px;
|
||||||
background-size: cover;
|
background-size: cover;
|
||||||
background-position: center;
|
background-position: center;
|
||||||
background-color: rgba(0,0,0,.05);
|
|
||||||
border-radius: 100%;
|
border-radius: 100%;
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
vertical-align: bottom;
|
vertical-align: bottom;
|
||||||
|
@ -7486,7 +7485,6 @@ label + .wizard-buttonList {
|
||||||
border-radius: 100%;
|
border-radius: 100%;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
margin: 0 10px;
|
margin: 0 10px;
|
||||||
background: hsl(210,17%,98%);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.cropper-container {
|
.cropper-container {
|
||||||
|
|
Loading…
Reference in a new issue