001/* 002 * (C) Copyright 2007 Nuxeo SAS (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.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 * $Id$ 018 */ 019package org.nuxeo.ecm.platform.picture.api; 020 021import java.io.File; 022import java.io.IOException; 023import java.io.InputStream; 024import java.util.List; 025import java.util.Map; 026 027import org.nuxeo.ecm.core.api.Blob; 028import org.nuxeo.ecm.core.api.DocumentModel; 029 030/** 031 * @author Max Stepanov 032 */ 033public interface ImagingService { 034 035 /** 036 * Returns the registered picture conversions. 037 * 038 * @since 7.1 039 */ 040 List<PictureConversion> getPictureConversions(); 041 042 /** 043 * Returns a {@link org.nuxeo.ecm.platform.picture.api.PictureConversion} given its {@code id}. 044 * 045 * @since 7.1 046 */ 047 PictureConversion getPictureConversion(String id); 048 049 /** 050 * Crops an image. 051 */ 052 Blob crop(Blob blob, int x, int y, int width, int height); 053 054 /** 055 * Resizes image. 056 */ 057 Blob resize(Blob blob, String finalFormat, int width, int height, int depth); 058 059 /** 060 * Rotates an image. 061 * 062 * @param blob a Blob containing the image 063 * @param angle the angle of the rotation 064 * @return a Blob holding the rotated image 065 */ 066 Blob rotate(Blob blob, int angle); 067 068 /** 069 * Retrieves metadata from an image contained in a {@link Blob}. 070 * 071 * @return the image metadata as a map String -> Object 072 * @deprecated since 7.2. Please use instead 073 * {@link org.nuxeo.binary.metadata.api.BinaryMetadataService#readMetadata(Blob)} 074 */ 075 Map<String, Object> getImageMetadata(Blob blob); 076 077 /** 078 * Returns the mime-type for the given file. 079 */ 080 String getImageMimeType(File file); 081 082 /** 083 * Returns the mime-type for the given Blob 084 * 085 * @since 5.7 086 */ 087 String getImageMimeType(Blob blob); 088 089 /** 090 * Retrieves the {@link ImageInfo} of the {@link Blob} that is received as parameter. 091 * <p> 092 * The information provided by the <b>ImageInfo</b>, like width, height or format, is obtained using ImageMagick 093 * (see http://www.imagemagick.org/script/index.php for more details on ImageMagick). 094 * 095 * @param blob the blob of a picture 096 * @return the {@link ImageInfo} of a blob 097 */ 098 ImageInfo getImageInfo(Blob blob); 099 100 /** 101 * Returns the value a configuration which name is received as parameter. 102 * 103 * @param configurationName the name of the configuration 104 * @return the value of the configuration, which can be null in case no configuration with the specified name was 105 * registered 106 */ 107 String getConfigurationValue(String configurationName); 108 109 /** 110 * Returns the value a configuration which name is received as parameter. In case no configuration with the 111 * specified name was registered, the received <b>defaultValue</b> parameter will be returned. 112 * 113 * @param configurationName the name of the configuration 114 * @param defaultValue the value of the configuration 115 */ 116 String getConfigurationValue(String configurationName, String defaultValue); 117 118 /** 119 * Sets the value of a configuration which could be used by the ImagingService. 120 * 121 * @param configurationName the name of the configuration 122 * @param configurationValue the value of the configuration 123 */ 124 void setConfigurationValue(String configurationName, String configurationValue); 125 126 /** 127 * Computes a {@link PictureView} for the given {@code blob} and {@code pictureConversion}. 128 * 129 * @param convert true if the {@code blob} is converted to fit the {@code pictureConversion}, false if the 130 * {@code blob} is put as it in the PictureView (without any conversion) 131 * @return the computed picture view 132 * @since 5.7 133 */ 134 PictureView computeViewFor(Blob blob, PictureConversion pictureConversion, boolean convert) throws IOException; 135 136 /** 137 * Computes a {@link PictureView} for the given {@code blob} and {@code pictureConversion}. 138 * 139 * @param imageInfo the {@code ImageInfo} to use when computing the view 140 * @param convert true if the {@code blob} is converted to fit the {@code pictureConversion}, false if the 141 * {@code blob} is put as it in the PictureView (without any conversion) 142 * @return the computed picture view 143 * @since 5.7 144 */ 145 PictureView computeViewFor(Blob blob, PictureConversion pictureConversion, ImageInfo imageInfo, boolean convert) 146 throws IOException; 147 148 /** 149 * Computes a List of {@link PictureView}s for the given {@code blob} and {@code pictureConversions}. 150 * 151 * @param convert true if the {@code blob} is converted to fit each {@code PictureConversion}, false if the 152 * {@code blob} is put as it in the PictureView (without any conversion) 153 * @return the computed picture views as a List of {@code PictureView}s 154 * @since 5.7 155 */ 156 List<PictureView> computeViewsFor(Blob blob, List<PictureConversion> pictureConversions, boolean convert) 157 throws IOException; 158 159 /** 160 * Computes a List of {@link PictureView}s for the given {@code blob} and {@code pictureConversions}. 161 * 162 * @param imageInfo the {@code ImageInfo} to use when computing the view 163 * @param convert true if the {@code blob} is converted to fit each {@code PictureConversion}, false if the 164 * {@code blob} is put as it in the PictureView (without any conversion) 165 * @return the computed picture views as a List of {@code PictureView}s 166 * @since 5.7 167 */ 168 List<PictureView> computeViewsFor(Blob blob, List<PictureConversion> pictureConversions, ImageInfo imageInfo, 169 boolean convert) throws IOException; 170 171 /** 172 * Computes a List of all {@link PictureView}s for each {@link Blob} of {@code blobs}. 173 * 174 * @param convert true if the {@code blob} is converted to fit each {@code PictureConversion}, false if the 175 * {@code blob} is put as it in the PictureView (without any conversion) 176 * @since 5.7 177 */ 178 List<List<PictureView>> computeViewsFor(List<Blob> blobs, List<PictureConversion> pictureConversions, 179 boolean convert) throws IOException; 180 181 /** 182 * Computes a List of all {@link PictureView}s for each {@link Blob} of {@code blobs}. 183 * 184 * @param imageInfo the {@code ImageInfo} to use when computing the view 185 * @param convert true if the {@code blob} is converted to fit each {@code PictureConversion}, false if the 186 * {@code blob} is put as it in the PictureView (without any conversion) 187 * @since 5.7 188 */ 189 List<List<PictureView>> computeViewsFor(List<Blob> blobs, List<PictureConversion> pictureConversions, 190 ImageInfo imageInfo, boolean convert) throws IOException; 191 192 /** 193 * Compute all the registered {@link PictureConversion} For each picture template the 194 * {@link ImagingService#computeViewFor(Blob, PictureConversion, ImageInfo, boolean)} method is call 195 * 196 * @since 7.1 197 */ 198 List<PictureView> computeViewsFor(DocumentModel doc, Blob blob, ImageInfo imageInfo, boolean convert) throws IOException; 199 200}