]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/helpers/image-utils.ts
Remove exif tags when processing images
[github/Chocobozzz/PeerTube.git] / server / helpers / image-utils.ts
index c4704b189fad7967364910a0d2673a0a2bd9f803..28d8fff4cb831fe8dcd24f17955ae9d532f35c03 100644 (file)
@@ -1,6 +1,7 @@
 import { copy, readFile, remove, rename } from 'fs-extra'
 import Jimp, { read } from 'jimp'
-import { buildUUID, getLowercaseExtension } from '@shared/core-utils'
+import { getLowercaseExtension } from '@shared/core-utils'
+import { buildUUID } from '@shared/extra-utils'
 import { convertWebPToJPG, processGIF } from './ffmpeg-utils'
 import { logger } from './logger'
 
@@ -79,6 +80,8 @@ async function autoResize (options: {
   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 ] } ])
@@ -105,6 +108,7 @@ function skipProcessing (options: {
   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
 
@@ -115,3 +119,11 @@ function skipProcessing (options: {
 
   return imageBytes <= 15 * kB
 }
+
+function hasExif (image: Jimp) {
+  return !!(image.bitmap as any).exifBuffer
+}
+
+function removeExif (image: Jimp) {
+  (image.bitmap as any).exifBuffer = null
+}