Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/abecms/abecms
Browse files Browse the repository at this point in the history
  • Loading branch information
gregorybesson committed Mar 27, 2017
2 parents 7b3d4a5 + 082fd65 commit 84bd949
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
2 changes: 2 additions & 0 deletions docs/types/abe-image.md
Expand Up @@ -45,6 +45,8 @@ uploading a image named *my_image.jpg* will create a thumbs by default named my_

if the tag contains ```thumbs='250x250,350x350'``` this will also create *my_image_thumb_250x250.jpg* & *my_image_thumb_350x350.jpg*

if the tag contains ```thumbs='250x'``` or ```thumbs='x250'``` this will create an image that have the with / height specified and the other side no specified will be resized to keep the same ratio as the original image

###Important

thumb are created using https://github.com/jwagner/smartcrop-cli which require to have imagemagick installed on your computer, if you don't a fallback library full JS is used (https://github.com/oliver-moran/jimp) but doesn't crop in a smart way your images
16 changes: 13 additions & 3 deletions src/cli/cms/media/image.js
Expand Up @@ -45,14 +45,24 @@ export function cropAndSaveFiles(images, file, resp) {
size: image
})

let newWidth = image.split('x')[0]
let newHeight = image.split('x')[1]
let splitedImage = image.split('x')
let newWidth = null
let newHeight = null

if(splitedImage[0] != null && splitedImage[0] != '') newWidth = parseInt(image.split('x')[0])
if(splitedImage[1] != null && splitedImage[1] != '') newHeight = parseInt(image.split('x')[1])

Jimp.read(file).then(function (originalImage) {
var originalWidth = originalImage.bitmap.width
var originalHeight = originalImage.bitmap.height
var ratio = originalWidth*newHeight/newWidth
if(parseInt(ratio - 1) <= parseInt(originalHeight) && parseInt(ratio + 1) >= parseInt(originalHeight)){
if(newWidth === null || newHeight === null){
originalImage.resize(newWidth != null ? newWidth : Jimp.AUTO, newHeight != null ? newHeight : Jimp.AUTO).write(newFile)
if(++cropedImage === length) {
resolve(resp)
}
}
else if(parseInt(ratio - 1) <= parseInt(originalHeight) && parseInt(ratio + 1) >= parseInt(originalHeight)){
originalImage.resize(parseInt(image.split('x')[0]), parseInt(image.split('x')[1])).write(newFile)
if(++cropedImage === length) {
resolve(resp)
Expand Down

0 comments on commit 84bd949

Please sign in to comment.