0

I have Kafka messages sending face of the person in crowd. I want to crop a specific portion of this image based on co-ordinates provided. How can I do this in NiFi? Do I need to use imagemagick on Windows NT and in linux the following command: mogrify -crop {Width}x{Height}+{X}+{Y} +repage image.png?

Execute this command using - ExecuteStreamCommand processor?

I refer to : Command line batch image cropping tool

fmw42
  • 46,825
  • 10
  • 62
  • 80
Yeshwant KAKAD
  • 279
  • 1
  • 6
  • 16
  • 1
    If you use imagemagick, you should use convert rather than mogrify. The latter is for processing a whole folder of images, though it can be used for one image. The convert command would be `convert image.png -crop {Width}x{Height}+{X}+{Y} +repage result.png`. I do not suggest saving over the original name unless you have a backup. – fmw42 Jan 08 '19 at 07:18
  • can you suggest me other ways apart from using imagemagick? – Yeshwant KAKAD Jan 08 '19 at 07:19
  • 1
    Sorry, I do not know either Kafka or Nifi. So I cannot suggest other tools. But Imagemagick is very easy and simple to do what you want. Other tools may be more complex and require more programming. In Python, you can use Wand, which is also based upon Imagemagick. As is mini_magick. So there are a lot of tools that are based upon Imagemagick. With PHP, use Imagick, which is also based upon Imagemagick. – fmw42 Jan 08 '19 at 07:21

1 Answers1

1

you can use ExecuteGroovyScript processor with following code:

import java.awt.image.BufferedImage
import javax.imageio.ImageIO


def ff = session.get()
if(!ff)return

ff.write{rawIn, rawOut->
    BufferedImage img = ImageIO.read(rawIn) //read image from flowfile input stream
    def x=100,y=200,endX=800,endY=600
    img = img.getSubimage(x, y, endX, endY) //crop
    ImageIO.write(img, "png", rawOut)       //write transformed image into flowfile as PNG
}

REL_SUCCESS << ff //transfer to success
daggett
  • 26,404
  • 3
  • 40
  • 56