1

I need a programmatic way to embed a clipping-path (saved as SVG file) to another image such as JPG/TIF/PSD. Using a tool such as Photoshop, this can be done easily and the path will be inserted in the image 8BIM profile, but it seems there is no way to do it programmatically. ImageMagick allows you to get a vector image for example by using the following command:

identify -format "%[8BIM:1999,2998:#1]" test.jpg > test.svg

But it seems not possible to do the reverse operation and add a vector image. Can anyone suggest any libraries which allow this operation?

Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
Elras
  • 19
  • 1
  • 4
  • 1
    It's probably easier to insert into a JPEG because the segments are self-contained and independent of one another unlike TIFFs which have offsets which would be messed up by inserting a new 8BIM chunk. – Mark Setchell Feb 18 '21 at 18:50
  • 2
    Please consider sharing some sample files with embedded 8BIM profiles - probably via Dropbox or Google Drive as imgur strips/modifies them. – Mark Setchell Feb 18 '21 at 19:50
  • Of course, here you can find images of a very small square with an 8BIM path and without path, the path is also provided as a svg file: https://drive.google.com/drive/folders/1qMWzA0_ex90WCbvW98nllWaW-M9gd1pu?usp=sharing – Elras Feb 18 '21 at 20:20

1 Answers1

1

It's a bit more code than I feel like writing for the moment, but it should be possible to put an 8BIM into a JPEG using the following information.

  • The anatomy of a JPEG is described here and here.

  • You can use PIL or OpenCV to encode a JPEG into a memory buffer and then locate and modify/add segments (such as an 8BIM) using code like this. Or you could just read() in an existing JPEG that you want to modify. To insert a segment, just write the first few segments to disk, then write your new one followed by the remaining segments from the existing file that you read at the start.

  • You can construct an 8BIM segment to insert using this answer.

  • You can use exiftool -v -v -v to see where an 8BIM appears in a JPEG created by Photoshop and then put yours in a similar place. You can also, obviously, equally use exiftool to see where/how your own attempt has landed.

Mark Setchell
  • 191,897
  • 31
  • 273
  • 432