2015-01-05 11 views
1

내 프로젝트 중 하나입니다. im4java 라이브러리를 사용하고 graphicsmagick을 통해 명령을 보내고 있습니다.graphicsmagick으로 이미지 크기 얻기

identify -format \"%w,%h,\" test.png 

내가 다음과 같은 결과까지 제대로 크기를 얻을 수 있습니다 :

는 이미지 크기를 얻을 수 있습니다. 이번에 stderr는 결과를 변경합니다 :

[wx=0.345750, wy=0.358550, rx=0.648500, ry=0.330880 
gx=0.321210, gy=0.597870, bx=0.155890, by=0.066040 
163, 70, 
identify: Ignoring incorrect cHRM value when sRGB is also present ] 

이미지 크기를 얻고 stderr 결과를 무시하는 방법은 무엇입니까? 사전에

감사

답변

-1

시도 같은 오류 메시지를 표시하는 명령에 -quiet를 추가 :

identify -quiet -format \"%w,%h,\" test.png 
0

를 다음을 수행하십시오

하는 -format의 \을 식별하는 "폭 = %를 승 , height = % h, \ "test.png

그런 다음 결과를 구문 분석하여 width = N 및 height = N을 찾으십시오.

0

// 나를 위해 "ping"이 차원을 가져 오는 가장 빠른 방법입니다.

 String resultFormat = "%w" + " " + "%h"; 
     ArrayListOutputConsumer outputConsumer = new ArrayListOutputConsumer(); 

     IdentifyCmd identify = new IdentifyCmd(); 

     identify.setOutputConsumer(outputConsumer); 
     IMOperation op = new IMOperation(); 
     op.ping(); 
     op.format(resultFormat); 
     op.addImage("abc.jpg"); 

     //Object[] arguments = new String[]{filePath}; 

     try { 
       identify.createScript("c:\\_work\\temp\\magick-dimension.sh.txt", op); // this will show you the actual im4java generated command 
       identify.run(op); 

     } catch (IOException | InterruptedException | IM4JavaException e) { 
       //throw new ImageAccessException(e.getMessage(), e); 
       e.printStackTrace(); 
     } 

     ArrayList<String> output = outputConsumer.getOutput(); 

     String[] dimensions = output.get(0).split(separator); 
     Dimension result = new Dimension(Integer.valueOf(dimensions[0]), Integer.valueOf(dimensions[1])); 
     return result;