File tree Expand file tree Collapse file tree 4 files changed +53
-0
lines changed
main/java/org/fugerit/java/codesamples/itext2 Expand file tree Collapse file tree 4 files changed +53
-0
lines changed Original file line number Diff line number Diff line change 1+ package org .fugerit .java .codesamples .itext2 ;
2+
3+ import com .lowagie .text .Element ;
4+ import com .lowagie .text .Image ;
5+ import org .fugerit .java .core .function .SafeFunction ;
6+
7+ public class LoadImage {
8+
9+ private LoadImage () {}
10+
11+ public static Image fromBytes ( byte [] data ) {
12+ return SafeFunction .get ( () -> {
13+ Image image = Image .getInstance ( data );
14+ image .scaleAbsoluteHeight (70 );
15+ image .scaleAbsoluteWidth (70 );
16+ image .setAlignment (Element .ALIGN_CENTER );
17+ return image ;
18+ } );
19+ }
20+
21+ }
Original file line number Diff line number Diff line change 1+ package codesamples ;
2+
3+ import com .lowagie .text .Image ;
4+ import lombok .extern .slf4j .Slf4j ;
5+ import org .fugerit .java .codesamples .itext2 .LoadImage ;
6+ import org .fugerit .java .core .io .StreamIO ;
7+ import org .fugerit .java .core .lang .helpers .ClassHelper ;
8+ import org .junit .jupiter .api .Assertions ;
9+ import org .junit .jupiter .api .Test ;
10+
11+ import java .io .InputStream ;
12+
13+ @ Slf4j
14+ class TestLoadImage {
15+
16+ private static final String [] IMAGES = { "logo1.png" , "logo2.png" };
17+
18+ @ Test
19+ void testFromBytes () {
20+ for ( String current : IMAGES ) {
21+ String currentTest = "test_image/" +current ;
22+ try (InputStream is = ClassHelper .loadFromDefaultClassLoader ( currentTest ) ) {
23+ log .info ( "currentTest {} - {}" , LoadImage .class .getName (), currentTest );
24+ Image img = LoadImage .fromBytes (StreamIO .readBytes ( is ) );
25+ Assertions .assertNotNull ( img );
26+ } catch (Exception e ) {
27+ log .warn ( "Errore " +e , e );
28+ }
29+ }
30+ }
31+
32+ }
You can’t perform that action at this time.
0 commit comments