title: How to implement .psd to .jpg conversion using ImageMagick for a batch of files using Java
body: <p>I need to view .psd images in swing so I decided to convert that into .jpg and try to show it.</p>
  
  <pre><code> My terminal command for single .psd to .jpg
  
   convert image.psd image.jpg (this is creating three images image-0.jpg,image-1.jpg,image-2.jpg)
  </code></pre>
  
  <p>but if I used </p>
  
  <pre><code> convert image.psd[0] image.jpg (this gives me correct output)
  </code></pre>
  
  <p>But i need to convert .psd images using java. i tried this but it is not working</p>
  
  <pre><code>if (new File(_imageicon[i].toString()).getName().endsWith(".psd") || 
          new File(_imageicon[i].toString()).getName().endsWith(".PSD")) {
      File psdFile = new File(_imageicon[i].toString());
      if(psdFile.exists()) {
          System.out.println("_imageicon[i].toString()"+_imageicon[i].toString());               
          System.out.println("_imageicon[i].toString().replace"+_imageicon[i].toString().replace(".psd", ".jpg").replace(".PSD", ".jpg"));
          ProcessBuilder pb = new ProcessBuilder("convert", _imageicon[i].toString() , _imageicon[i].toString().replace(".psd", ".jpg").replace(".PSD", ".jpg"));
          pb.redirectErrorStream(true);
          try {
              Process p = pb.start();
          } catch (IOException ex) {
              Logger.getLogger(GridEditor.class.getName()).log(Level.SEVERE, null, ex);
          }
  
          ImageIcon ii = new ImageIcon(_imageicon[i].toString().replace(".psd", ".jpg").replace(".PSD", ".jpg"));
          Image imagepdf1 = ii.getImage();
          Image newimg = imagepdf1.getScaledInstance(100, 60, java.awt.Image.SCALE_SMOOTH);
          ii = new ImageIcon(newimg);
          _lbl[i].setIcon(ii);
      }
  }
  </code></pre>
  
  <p>Any idea please suggest.</p>