Guest User

Untitled

a guest
Jul 22nd, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using System.Linq;
  4. using ImageSharp;
  5. using SixLabors.Primitives;
  6.  
  7. namespace fix
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. // reduced resolution camera JPEGs
  14. var smalls = Directory.GetFiles("path/S").OrderBy(p => p);
  15. // target path for fixed files
  16. var tPath = "path/T/";
  17.  
  18. foreach (var path in smalls)
  19. {
  20. using (FileStream sStream = File.OpenRead(path))
  21. // full resolution JPEGs from RAWs
  22. using (FileStream lStream = File.OpenRead(path.Replace("/S/", "/L/")))
  23. {
  24. var small = Image.Load(sStream);
  25. var large = Image.Load(lStream);
  26. Rectangle rect = new Rectangle();
  27.  
  28. // image height of the reduced resolution image with in-camera cropping
  29. // it's always height, the portrait (2:3) mode is only in EXIF
  30. if (small.Height == 1360)
  31. {
  32. // crop rectangle on the full resolution image (see above)
  33. rect = new Rectangle(0, 168, 4000, 2664);
  34. }
  35.  
  36. // this file has been cropped
  37. if (rect.Width != 0)
  38. {
  39. using (FileStream tStream = File.OpenWrite(string.Format("{0}{1}", tPath, Path.GetFileName(path))))
  40. {
  41. var encoder = new ImageSharp.Formats.JpegEncoder();
  42. encoder.Quality = 98; // as desired
  43. large.Crop(rect).Save(tStream, encoder);
  44. }
  45. }
  46. }
  47. }
  48. }
  49. }
  50. }
Add Comment
Please, Sign In to add comment