ubik23 / charactercreator

A frontend interface for creating characters in SVG.
Other
307 stars 78 forks source link

SUGGESTION: URI in the meta data of SVG.PNG files #212

Open saxtron3000 opened 2 years ago

saxtron3000 commented 2 years ago

This way, users can redraw/modify their character from a downloaded image.

millette commented 2 years ago

SVG already supports this (URL written to Copyright meta data).

For png, see https://sharp.pixelplumbing.com/api-output#withmetadata

https://exiftool.org https://www.npmjs.com/package/exiftool-vendored

Notes from https://exiftool.org/TagNames/EXIF.html:

ImageUniqueID string ExifIFD ImageDescription string IFD0

For png, also add Copyright info:

Copyright string IFD0 (may contain copyright notices for photographer and editor, separated by a newline. As per the EXIF specification, the newline is replaced by a null byte when writing to file, but this may be avoided by disabling the print conversion)

This would take care of writing the data. Reading and interpreting would be the next task.

millette commented 2 years ago

After a few tries it looks like sharp doesn't support png metadata. We have the option to save jpeg instead of png (smaller file - although compressed, the svg is always available for pristine quality) or turn to an external tool to save png metadata.

millette commented 2 years ago
const ExifTool = require("exiftool-vendored").ExifTool
const exiftool = new ExifTool({ taskTimeoutMillis: 500 })

async function runner() {
  await exiftool
    .write("oyoy-6.png", {
      "PNG:SOURCE": "https://charactercreator.org/#skinColor=%235c3836&irisColor=%23552200&hairColor=%231a1a1a&pupils=round&sex=m&body_head=oblong&ears=outstretched&nose=syrid&emotion=omg&shirt=turtleneck&shirtColor=%23BEE9C5&pants=cargo&pantsColor=%23b19f92&belt=utility&hat=chinese_farmer&hatColor=%23b19f92&glasses=round&shoes=loafers&tie=neck&tieColor=%23b19f92"
    })
  exiftool.end()
}

runner().catch(console.error)

Et on trouve le output:

{
  SourceFile: '/home/millette/exif/oyoy-6.png',
  errors: [],
  ExifToolVersion: 12.4,
  FileName: 'oyoy-6.png',
  Directory: '/home/millette/exif',
  FileSize: '111 KiB',
  FileModifyDate: ExifDateTime {
    year: 2022,
    month: 4,
    day: 9,
    hour: 14,
    minute: 48,
    second: 55,
    millisecond: 0,
    tzoffsetMinutes: -240,
    rawValue: '2022:04:09 14:48:55-04:00',
    zoneName: 'UTC-4'
  },
  FileAccessDate: ExifDateTime {
    year: 2022,
    month: 4,
    day: 9,
    hour: 14,
    minute: 48,
    second: 55,
    millisecond: 0,
    tzoffsetMinutes: -240,
    rawValue: '2022:04:09 14:48:55-04:00',
    zoneName: 'UTC-4'
  },
  FileInodeChangeDate: ExifDateTime {
    year: 2022,
    month: 4,
    day: 9,
    hour: 14,
    minute: 48,
    second: 55,
    millisecond: 0,
    tzoffsetMinutes: -240,
    rawValue: '2022:04:09 14:48:55-04:00',
    zoneName: 'UTC-4'
  },
  FilePermissions: '-rw-rw-r--',
  FileType: 'PNG',
  FileTypeExtension: 'png',
  MIMEType: 'image/png',
  ImageWidth: 1000,
  ImageHeight: 1000,
  BitDepth: 8,
  ColorType: 'RGB with Alpha',
  Compression: 'Deflate/Inflate',
  Filter: 'Adaptive',
  Interlace: 'Noninterlaced',
  PixelsPerUnitX: 2835,
  PixelsPerUnitY: 2835,
  PixelUnits: 'meters',
  Source: 'https://charactercreator.org/#skinColor=%235c3836&irisColor=%23552200&hairColor=%231a1a1a&pupils=round&sex=m&body_head=oblong&ears=outstretched&nose=syrid&emotion=omg&shirt=turtleneck&shirtColor=%23BEE9C5&pants=cargo&pantsColor=%23b19f92&belt=utility&hat=chinese_farmer&hatColor=%23b19f92&glasses=round&shoes=loafers&tie=neck&tieColor=%23b19f92',
  CodedCharacterSet: 'UTF8',
  EnvelopeRecordVersion: 4,
  ImageSize: '1000x1000',
  Megapixels: 1
}

Voici l'exemple png:

oyoy-6

millette commented 2 years ago

One more thing: webp format (supports non-lossy compression, à la png) works with sharp and it also supports exif metadata. It's probably the best option, if we wish to change image format.

saxtron3000 commented 2 years ago

What do you think Fred? Best to stick with PNG and SVG?

Pablo Saxtron, Operations

The Character Creator

https://charactercreator.org/

On Sat, Apr 9, 2022 at 3:27 PM Robin Millette @.***> wrote:

One more thing: webp format (supports non-lossy compression, à la png) works with sharp and it also supports exif metadata. It's probably the best option, if we wish to change image format.

— Reply to this email directly, view it on GitHub https://github.com/ubik23/charactercreator/issues/212#issuecomment-1094111550, or unsubscribe https://github.com/notifications/unsubscribe-auth/ATC4DBPZZZZMTCMKHHZDKE3VEHK3NANCNFSM5S5FYFVA . You are receiving this because you authored the thread.Message ID: @.***>