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 * Nuxeo - initial API and implementation 016 * 017 */ 018package org.nuxeo.ecm.platform.picture.magick.utils; 019 020import org.nuxeo.ecm.platform.commandline.executor.api.CmdParameters; 021import org.nuxeo.ecm.platform.commandline.executor.api.CommandException; 022import org.nuxeo.ecm.platform.commandline.executor.api.CommandLineExecutorService; 023import org.nuxeo.ecm.platform.commandline.executor.api.CommandNotAvailable; 024import org.nuxeo.ecm.platform.commandline.executor.api.ExecResult; 025import org.nuxeo.ecm.platform.picture.magick.MagickExecutor; 026import org.nuxeo.runtime.api.Framework; 027 028/** 029 * Unit command to crop a picture using ImageMagick. 030 * 031 * @author tiry 032 */ 033public class ImageCropper extends MagickExecutor { 034 035 public static void crop(String inputFilePath, String outputFilePath, int tileWidth, int tileHeight, int offsetX, 036 int offsetY) throws CommandNotAvailable, CommandException { 037 CommandLineExecutorService cles = Framework.getLocalService(CommandLineExecutorService.class); 038 CmdParameters params = cles.getDefaultCmdParameters(); 039 params.addNamedParameter("tileWidth", String.valueOf(tileWidth)); 040 params.addNamedParameter("tileHeight", String.valueOf(tileHeight)); 041 params.addNamedParameter("offsetX", String.valueOf(offsetX)); 042 params.addNamedParameter("offsetY", String.valueOf(offsetY)); 043 params.addNamedParameter("inputFilePath", inputFilePath); 044 params.addNamedParameter("outputFilePath", outputFilePath); 045 ExecResult res = cles.execCommand("crop", params); 046 if (!res.isSuccessful()) { 047 throw res.getError(); 048 } 049 } 050 051}