001/*
002 * (C) Copyright 2006-2015 Nuxeo SA (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl-2.1.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *     troger
016 *
017 */
018
019package org.nuxeo.ecm.platform.picture.magick.utils;
020
021import org.nuxeo.ecm.platform.commandline.executor.api.CmdParameters;
022import org.nuxeo.ecm.platform.commandline.executor.api.CommandException;
023import org.nuxeo.ecm.platform.commandline.executor.api.CommandLineExecutorService;
024import org.nuxeo.ecm.platform.commandline.executor.api.CommandNotAvailable;
025import org.nuxeo.ecm.platform.commandline.executor.api.ExecResult;
026import org.nuxeo.ecm.platform.picture.magick.MagickExecutor;
027import org.nuxeo.runtime.api.Framework;
028
029/**
030 * @author <a href="mailto:troger@nuxeo.com">Thomas Roger</a>
031 */
032public class ImageConverter extends MagickExecutor {
033
034    public static void convert(String inputFilePath, String outputFilePath) throws CommandNotAvailable,
035            CommandException {
036        CommandLineExecutorService cles = Framework.getLocalService(CommandLineExecutorService.class);
037        CmdParameters params = cles.getDefaultCmdParameters();
038        params.addNamedParameter("inputFilePath", inputFilePath);
039        params.addNamedParameter("outputFilePath", outputFilePath);
040        ExecResult res = cles.execCommand("converter", params);
041        if (!res.isSuccessful()) {
042            throw res.getError();
043        }
044    }
045
046}