Skip to content

Commit

Permalink
Convert images back to base64 before reinserting them.
Browse files Browse the repository at this point in the history
  • Loading branch information
brianloveswords committed Dec 3, 2013
1 parent d992348 commit b7a5d78
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion models/badge-image.js
Expand Up @@ -46,7 +46,8 @@ BadgeImage.prototype.bakeAndSave = function (globalCallback) {
}.bind(this)

const saveImage = function saveImage(bakedImageData, callback) {
this.set('image_data', bakedImageData)
const b64image = Buffer(bakedImageData).toString('base64')
this.set('image_data', b64image)
this.set('baked', true)
this.save(callback)
}.bind(this)
Expand Down
8 changes: 8 additions & 0 deletions test/badge-image-model.test.js
Expand Up @@ -45,6 +45,14 @@ $.prepareDatabase({
badgeimage.bakeAndSave(function (err, image) {
t.notOk(err, 'no error')

const isRawPng =
image
.get('image_data')
.toString('utf8')
.slice(1, 4) == 'PNG'

t.notOk(isRawPng, 'should not be a raw PNG')

const bakedData = image.toBuffer()
t.ok(image.get('baked'), 'image says its baked')
t.notOk(bakedData == unbakedData, 'not the same')
Expand Down

0 comments on commit b7a5d78

Please sign in to comment.