Program.cs 894 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using ImageMagick;
  2. using System.Text;
  3. #if DEBUG
  4. Console.Write("Debug,Input file path:");
  5. var filePath = Console.ReadLine();
  6. #else
  7. if (args.Length != 1)
  8. {
  9. Console.Error.WriteLine("ERR: 1 file required from args");
  10. return 1;
  11. }
  12. var filePath = args[0];
  13. #endif
  14. var image = new MagickImage(filePath);
  15. var parameters = image.GetAttribute("parameters");
  16. if (parameters != null)
  17. {
  18. Console.WriteLine(parameters);
  19. }
  20. else
  21. {
  22. var x = image.GetExifProfile();
  23. if (x == null)
  24. {
  25. Console.Error.WriteLine("ERR: no exif profile found");
  26. return 2;
  27. }
  28. var p = new ExifProfile(x.ToByteArray()!);
  29. var v = p.GetValue(ExifTag.UserComment);
  30. if (v == null)
  31. {
  32. Console.Error.WriteLine("ERR: no exif UserComment found");
  33. return 3;
  34. }
  35. var s = Encoding.BigEndianUnicode.GetString(v.Value[8..]);
  36. Console.WriteLine(s);
  37. }
  38. return 0;