[Image Processing] file system (based on thumbnailator) Collector's Edition - One

Many system development process will encounter files related processing, recently easily develop a small file system encountered a thumbnail picture of demand, the need to provide at the time of display of thumbnails download time providing artwork, we think of direct java may be built-in picture processing class, but the process is too complex to meet demand, support is not very good, especially in terms of watermarks, old, fat wheels directly, then good ~

Today's brief wheels it:

thumbnailator

  • google development and maintenance
  • github Open Source
  • Do not rely on external libraries
  • Operating super-simple (really super simple)

action

ONE . In accordance with the original narrow (Original 001.jpg -> 002.jpg):

Thumbnails.of(new File("F://001.jpg"))
              .size(500, 500)
              .toFile(new File("F://002.jpg"));

Original Size: 6848 KB -> 42 KB new view (the same proportion, see below)

new map


TWO . According enlarged picture (picture 001.jpg -> 002.jpg):

Thumbnails.of(new File("F://002.jpg"))
              .size(1500, 1500)
              .toFile(new File("F://003.jpg"));

Original Size: 42 KB -> 174 KB new view (the same proportion, below)

new map


In addition to convenient zoom generated directly outside the file.
Can also convert file formats support direct generate an output flow, etc., the code:

OutputStream os = ...;
        
Thumbnails.of("F://001.jpg")
        .size(200, 200)
        .outputFormat("png")
        .toOutputStream(os);

Compared to the original plan is not a thief easy, basically no more than 5 lines of code to solve the problem 50 rows may not be able to solve, share here today, to see usage share more thumbnailator behind.

In fact, many times, we just need to fish rather than fishing, na, give you fish.

TO BE CONTINUE!
Public concern number watermelon_code get first-hand to meet ~

Guess you like

Origin www.cnblogs.com/wdssdream/p/11456596.html