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 * btatar 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 * Unit command to rotate a picture. 031 * 032 * @author btatar 033 */ 034public class ImageRotater extends MagickExecutor { 035 036 public static void rotate(String inputFile, String outputFile, int angle) throws CommandNotAvailable, 037 CommandException { 038 CommandLineExecutorService cles = Framework.getLocalService(CommandLineExecutorService.class); 039 CmdParameters params = cles.getDefaultCmdParameters(); 040 params.addNamedParameter("angle", String.valueOf(angle)); 041 params.addNamedParameter("inputFilePath", inputFile); 042 params.addNamedParameter("outputFilePath", outputFile); 043 ExecResult result = cles.execCommand("rotate", params); 044 if (!result.isSuccessful()) { 045 throw result.getError(); 046 } 047 } 048 049}