/*
 * (C) Copyright 2006-2008 Nuxeo SAS (http://nuxeo.com/) and contributors.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser General Public License
 * (LGPL) version 2.1 which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/lgpl.html
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * Contributors:
 *     Nuxeo - initial API and implementation
 *
 * $Id$
 *
 */
package org.nuxeo.ecm.platform.picture.magick.utils;

import org.nuxeo.ecm.platform.commandline.executor.api.CmdParameters;
import org.nuxeo.ecm.platform.commandline.executor.api.CommandNotAvailable;
import org.nuxeo.ecm.platform.commandline.executor.api.ExecResult;
import org.nuxeo.ecm.platform.picture.api.ImageInfo;
import org.nuxeo.ecm.platform.picture.magick.MagickExecutor;

/**
 * Unit command to extract information from a picture file.
 *
 * @author tiry
 */
public class ImageIdentifier extends MagickExecutor {

    public static ImageInfo getInfo(String inputFilePath)
            throws CommandNotAvailable {
        CmdParameters params = new CmdParameters();
        params.addNamedParameter("inputFilePath", inputFilePath);
        ExecResult result = execCommand("identify", params);

        String out = result.getOutput().get(
                result.getOutput().size() > 1 ? result.getOutput().size() - 1
                        : 0);
        String[] res = out.split(" ");

        return new ImageInfo(res[1], res[2], res[0], res[res.length - 1],
                inputFilePath);
    }

}

@@ -1303,24 +1303,25 @@
 lable %7B%0A
+%0A
         
 CmdParam
@@ -1316,179 +1316,61 @@
     
-CmdParameters params = new CmdParameters();%0A        params.addNamedParameter(%22inputFilePath%22, inputFilePath);%0A        ExecResult result = execCommand(%22identify%22, params);%0A
+ExecResult result = getIdentifyResult(inputFilePath);
 %0A   
@@ -1672,10 +1672,294 @@
 %0A    %7D%0A%0A
+    public static ExecResult getIdentifyResult(String inputFilePath)%0A            throws CommandNotAvailable %7B%0A%0A        CmdParameters params = new CmdParameters();%0A        params.addNamedParameter(%22inputFilePath%22, inputFilePath);%0A        return execCommand(%22identify%22, params);%0A    %7D%0A%0A
 %7D%0A

Add ImageIdentifier#getIdentifyResult(String inputFilePath) to detect if a file is an image given its path