Advertisement
pharmokan

image nodejs

Apr 10th, 2020
368
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. import * as path from "path";
  2. import * as fs from "fs";
  3. import * as sizeOf from "image-size";
  4. import * as sharp from "sharp";
  5. let imagePath = path.win32.normalize(process.argv[2].split("'")[1]);
  6. //process.chdir(imagePath);
  7. //var dimensions = sizeOf.default("");
  8. //console.log(dimensions.height > dimensions.width);
  9.  
  10. // $ node test.js "C:\Users\dan"
  11. // ==> C:\Users\dan\Pictures\ss\
  12.  
  13. let input = "h.jpg";
  14. sharp
  15. .default(input)
  16. .resize(2000, 1200, {
  17. fit: "outside",
  18. })
  19. .toFile("output-outside-h-2000-1200.jpg");
  20.  
  21. input = "w.jpg";
  22. sharp
  23. .default(input)
  24. .resize(2000, 1200, {
  25. fit: "outside",
  26. })
  27. .toFile("output-outside-w-2000-1200.jpg");
  28.  
  29. input = "w.jpg";
  30. sharp
  31. .default(input)
  32. .resize(1200, 2000, {
  33. fit: "outside",
  34. })
  35. .toFile("output-outside-w-1200-2000.jpg");
  36.  
  37. input = "h.jpg";
  38. sharp
  39. .default(input)
  40. .resize(1200, 2000, {
  41. fit: "outside",
  42. })
  43. .toFile("output-outside-h-1200-2000.jpg");
  44.  
  45. input = "w.jpg";
  46. sharp
  47. .default(input)
  48. .resize(1200, 2000, {
  49. fit: "inside",
  50. })
  51. .toFile("output-inside-w-1200-2000.jpg");
  52.  
  53. input = "h.jpg";
  54. sharp
  55. .default(input)
  56. .resize(1200, 2000, {
  57. fit: "inside",
  58. })
  59. .toFile("output-inside-h-1200-2000.jpg");
  60.  
  61. input = "h.jpg";
  62. sharp
  63. .default(input)
  64. .resize(2000, 1200, {
  65. fit: "inside",
  66. })
  67. .toFile("output-inside-h-2000-1200.jpg");
  68.  
  69. input = "w.jpg";
  70. sharp
  71. .default(input)
  72. .resize(2000, 1200, {
  73. fit: "inside",
  74. })
  75. .toFile("output-inside-w-2000-1200.jpg");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement