const sourceIsPortrait = sourceImage.getWidth() < sourceImage.getHeight()
const destIsPortraitOrSquare = newSize.width <= newSize.height
+ removeExif(sourceImage)
+
if (sourceIsPortrait && !destIsPortraitOrSquare) {
const baseImage = sourceImage.cloneQuiet().cover(newSize.width, newSize.height)
.color([ { apply: 'shade', params: [ 50 ] } ])
const { sourceImage, newSize, imageBytes, inputExt, outputExt } = options
const { width, height } = newSize
+ if (hasExif(sourceImage)) return false
if (sourceImage.getWidth() > width || sourceImage.getHeight() > height) return false
if (inputExt !== outputExt) return false
return imageBytes <= 15 * kB
}
+
+function hasExif (image: Jimp) {
+ return !!(image.bitmap as any).exifBuffer
+}
+
+function removeExif (image: Jimp) {
+ (image.bitmap as any).exifBuffer = null
+}
import { expect } from 'chai'
import { readFile, remove } from 'fs-extra'
import { join } from 'path'
+import { execPromise } from '@server/helpers/core-utils'
import { buildAbsoluteFixturePath, root } from '@shared/core-utils'
import { processImage } from '../../../server/helpers/image-utils'
}
}
+async function hasTitleExif (path: string) {
+ const result = JSON.parse(await execPromise(`exiftool -json ${path}`))
+
+ return result[0]?.Title === 'should be removed'
+}
+
describe('Image helpers', function () {
const imageDestDir = join(root(), 'test-images')
- const imageDest = join(imageDestDir, 'test.jpg')
+
+ const imageDestJPG = join(imageDestDir, 'test.jpg')
+ const imageDestPNG = join(imageDestDir, 'test.png')
+
const thumbnailSize = { width: 223, height: 122 }
it('Should skip processing if the source image is okay', async function () {
const input = buildAbsoluteFixturePath('thumbnail.jpg')
- await processImage(input, imageDest, thumbnailSize, true)
+ await processImage(input, imageDestJPG, thumbnailSize, true)
- await checkBuffers(input, imageDest, true)
+ await checkBuffers(input, imageDestJPG, true)
})
it('Should not skip processing if the source image does not have the appropriate extension', async function () {
const input = buildAbsoluteFixturePath('thumbnail.png')
- await processImage(input, imageDest, thumbnailSize, true)
+ await processImage(input, imageDestJPG, thumbnailSize, true)
- await checkBuffers(input, imageDest, false)
+ await checkBuffers(input, imageDestJPG, false)
})
it('Should not skip processing if the source image does not have the appropriate size', async function () {
const input = buildAbsoluteFixturePath('preview.jpg')
- await processImage(input, imageDest, thumbnailSize, true)
+ await processImage(input, imageDestJPG, thumbnailSize, true)
- await checkBuffers(input, imageDest, false)
+ await checkBuffers(input, imageDestJPG, false)
})
it('Should not skip processing if the source image does not have the appropriate size', async function () {
const input = buildAbsoluteFixturePath('thumbnail-big.jpg')
- await processImage(input, imageDest, thumbnailSize, true)
+ await processImage(input, imageDestJPG, thumbnailSize, true)
+
+ await checkBuffers(input, imageDestJPG, false)
+ })
+
+ it('Should strip exif for a jpg file that can not be copied', async function () {
+ const input = buildAbsoluteFixturePath('exif.jpg')
+ expect(await hasTitleExif(input)).to.be.true
+
+ await processImage(input, imageDestJPG, { width: 100, height: 100 }, true)
+ await checkBuffers(input, imageDestJPG, false)
+
+ expect(await hasTitleExif(imageDestJPG)).to.be.false
+ })
+
+ it('Should strip exif for a jpg file that could be copied', async function () {
+ const input = buildAbsoluteFixturePath('exif.jpg')
+ expect(await hasTitleExif(input)).to.be.true
+
+ await processImage(input, imageDestJPG, thumbnailSize, true)
+ await checkBuffers(input, imageDestJPG, false)
+
+ expect(await hasTitleExif(imageDestJPG)).to.be.false
+ })
+
+ it('Should strip exif for png', async function () {
+ const input = buildAbsoluteFixturePath('exif.png')
+ expect(await hasTitleExif(input)).to.be.true
- await checkBuffers(input, imageDest, false)
+ await processImage(input, imageDestPNG, thumbnailSize, true)
+ expect(await hasTitleExif(imageDestPNG)).to.be.false
})
after(async function () {
- await remove(imageDest)
+ await remove(imageDestDir)
})
})