KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > quercus > lib > ExifModule


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  *
23  * Free Software Foundation, Inc.
24  * 59 Temple Place, Suite 330
25  * Boston, MA 02111-1307 USA
26  *
27  * @author Scott Ferguson
28  */

29
30 package com.caucho.quercus.lib;
31
32 import com.caucho.quercus.QuercusException;
33 import com.caucho.quercus.annotation.Optional;
34 import com.caucho.quercus.annotation.Reference;
35 import com.caucho.quercus.env.BooleanValue;
36 import com.caucho.quercus.env.Env;
37 import com.caucho.quercus.env.LongValue;
38 import com.caucho.quercus.env.Value;
39 import com.caucho.quercus.module.AbstractQuercusModule;
40 import com.caucho.util.L10N;
41 import com.caucho.vfs.Path;
42
43 import javax.imageio.ImageIO JavaDoc;
44 import javax.imageio.ImageReader JavaDoc;
45 import java.io.IOException JavaDoc;
46 import java.util.Iterator JavaDoc;
47
48
49 /**
50  * PHP exif
51  */

52 public class ExifModule extends AbstractQuercusModule {
53   private static final L10N L = new L10N(ExifModule.class);
54
55   /**
56    * Reads the EXIF headers from JPEG or TIFF
57    */

58   public static Value exif_read_data(Env env, Path file,
59                      @Optional String JavaDoc sections,
60                      @Optional boolean arrays,
61                      @Optional boolean thumbs)
62   {
63     return BooleanValue.FALSE;
64   }
65
66   /**
67    * Alias of exif_read_data()
68    */

69   public static Value read_exif_data(Env env, Path file,
70                      @Optional String JavaDoc sections,
71                      @Optional boolean arrays,
72                      @Optional boolean thumbs)
73   {
74     return exif_read_data(env, file, sections, arrays, thumbs);
75   }
76
77   /**
78    * Retrieve the embedded thumbnail of a TIFF or JPEG image
79    * @param filename the name of the image file being read.
80    * @param width the width of the returned thumbnail
81    * @param height the height of the returned thumbnail
82    * @param imagetype either TIFF or JPEG
83    * @return either the thumbnail or FALSE
84    */

85   public static Value exif_thumbnail(Env env, Path file,
86                      @Optional @Reference int width,
87                      @Optional @Reference int height,
88                      @Optional @Reference int imageType)
89   {
90     return BooleanValue.FALSE;
91   }
92
93   /**
94    * Get the header name for an index
95    */

96   public static String JavaDoc exif_tagname(String JavaDoc index)
97   {
98     return null;
99   }
100
101   /**
102    * Determine the type of an image
103    */

104   public static Value exif_imagetype(Env env, Path file)
105   {
106     try {
107       Iterator JavaDoc it = ImageIO.getImageReaders(file.openRead());
108       if (!it.hasNext())
109     return BooleanValue.FALSE;
110       ImageReader JavaDoc imageReader = (ImageReader JavaDoc)it.next();
111       if (it.hasNext())
112     throw new QuercusException("ImageIO returned two ImageReaders:\n "+
113                    imageReader+"\n "+it.next());
114       String JavaDoc formatName = imageReader.getFormatName();
115       if (formatName.equals("jpeg") || formatName.equals("jpg"))
116     return LongValue.create(ImageModule.IMAGETYPE_JPG);
117       if (formatName.equals("gif"))
118     return LongValue.create(ImageModule.IMAGETYPE_GIF);
119       if (formatName.equals("png"))
120     return LongValue.create(ImageModule.IMAGETYPE_PNG);
121       if (formatName.equals("swf"))
122     return LongValue.create(ImageModule.IMAGETYPE_SWF);
123       if (formatName.equals("psd"))
124     return LongValue.create(ImageModule.IMAGETYPE_PSD);
125       if (formatName.equals("bmp"))
126     return LongValue.create(ImageModule.IMAGETYPE_BMP);
127       if (formatName.equals("tiff"))
128     return LongValue.create(ImageModule.IMAGETYPE_TIFF_II);
129       /*
130       // XXX: check byte order
131       if (formatName.equals("tiff"))
132       return ImageModule.IMAGETYPE_TIFF_MM;
133       */

134       if (formatName.equals("jpc"))
135     return LongValue.create(ImageModule.IMAGETYPE_JPC);
136       if (formatName.equals("jp2"))
137     return LongValue.create(ImageModule.IMAGETYPE_JP2);
138       if (formatName.equals("jpf"))
139     return LongValue.create(ImageModule.IMAGETYPE_JPX);
140       if (formatName.equals("jb2"))
141     return LongValue.create(ImageModule.IMAGETYPE_JB2);
142       if (formatName.equals("swc"))
143     return LongValue.create(ImageModule.IMAGETYPE_SWC);
144       if (formatName.equals("iff"))
145     return LongValue.create(ImageModule.IMAGETYPE_IFF);
146       if (formatName.equals("wbmp"))
147     return LongValue.create(ImageModule.IMAGETYPE_WBMP);
148       if (formatName.equals("xbm"))
149     return LongValue.create(ImageModule.IMAGETYPE_XBM);
150       env.warning(L.l("ImageIO returned unknown image type: " + formatName));
151       return BooleanValue.FALSE;
152     }
153     catch (IOException JavaDoc e)
154       {
155     throw new QuercusException(e);
156       }
157   }
158
159
160
161 }
162
163
Popular Tags