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