Skip to content

Commit

Permalink
added logo centering
Browse files Browse the repository at this point in the history
  • Loading branch information
Luen committed Nov 4, 2021
1 parent d9be83c commit 8dc9a79
Show file tree
Hide file tree
Showing 4 changed files with 1,008 additions and 17 deletions.
Binary file added Wanderstories-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
58 changes: 42 additions & 16 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ app.get('*', function(req, res) {
const FILE_EXTENSION = ORIGINAL_IMAGE.split('.').pop().toLowerCase()

//const LOGO = "https://wanderstories.space/content/images/size/w1000/2016/06/Wander-Stories-logo.jpg"
const LOGO = "https://wanderstories.space/content/images/size/w1000/2021/11/Wanderstories-publication-logo.png"
//const LOGO = "https://wanderstories.space/content/images/size/w1000/2021/11/Wanderstories-publication-logo.png"
const LOGO = __dirname + "/Wanderstories-logo.png"

const LOGO_MARGIN_PERCENTAGE = 5
var LOCATION = 'Center' // or 'Bottom Right'

const ACCEPTED = [
'jpg',
Expand Down Expand Up @@ -47,21 +49,45 @@ app.get('*', function(req, res) {
Jimp.read(LOGO)
])

logo.resize(image.bitmap.width / 10, Jimp.AUTO)

const xMargin = (image.bitmap.width * LOGO_MARGIN_PERCENTAGE) / 100
const yMargin = (image.bitmap.width * LOGO_MARGIN_PERCENTAGE) / 100

const X = image.bitmap.width - logo.bitmap.width - xMargin
const Y = image.bitmap.height - logo.bitmap.height - yMargin

return image.composite(logo, X, Y, [
{
mode: Jimp.BLEND_SCREEN,
opacitySource: 0.1,
opacityDest: 1
}
])
if (LOCATION == 'Center') {
logo.resize(image.bitmap.width / 5, Jimp.AUTO)

const X = (image.bitmap.width / 2) - (logo.bitmap.width / 2)
const Y = (image.bitmap.height / 2) - (logo.bitmap.height / 2)

/*Jimp.BLEND_SOURCE_OVER;
Jimp.BLEND_DESTINATION_OVER;
Jimp.BLEND_MULTIPLY;
Jimp.BLEND_ADD; ---
Jimp.BLEND_SCREEN;
Jimp.BLEND_OVERLAY;
Jimp.BLEND_DARKEN;
Jimp.BLEND_LIGHTEN;
Jimp.BLEND_HARDLIGHT;
Jimp.BLEND_DIFFERENCE;
Jimp.BLEND_EXCLUSION;
*/

return image.composite(logo, X, Y, {
mode: Jimp.BLEND_ADD,
opacitySource: 0.2,
opacityDest: 1
})
} else { // Bottom Right
logo.resize(image.bitmap.width / 10, Jimp.AUTO)

const xMargin = (image.bitmap.width * LOGO_MARGIN_PERCENTAGE) / 100
const yMargin = (image.bitmap.height * LOGO_MARGIN_PERCENTAGE) / 100

const X = image.bitmap.width - logo.bitmap.width - xMargin
const Y = image.bitmap.height - logo.bitmap.height - yMargin

return image.composite(logo, X, Y, {
mode: Jimp.BLEND_SCREEN,
opacitySource: 0.5,
opacityDest: 1
})
}
}

// write file to server and send file
Expand Down
Loading

0 comments on commit 8dc9a79

Please sign in to comment.