[imageBLOB] Fixed issue 18082. Image size and mime type will be saved and reused to increase performance.
authorAntonio Moreno <antonio.moreno@openbravo.com>
Tue, 26 Jul 2011 18:10:49 +0200
changeset 13288 3f2583bb1884
parent 13287 cc03c38f8a61
child 13289 5ca30ea10898
[imageBLOB] Fixed issue 18082. Image size and mime type will be saved and reused to increase performance.
modules/org.openbravo.client.application/src/org/openbravo/client/application/window/ImagesActionHandler.java
src-db/database/model/tables/AD_IMAGE.xml
src-db/database/sourcedata/AD_COLUMN.xml
src-db/database/sourcedata/AD_ELEMENT.xml
src/org/openbravo/erpCommon/info/ImageInfoBLOB.java
src/org/openbravo/erpCommon/utility/ImageToDatabaseLoader.java
src/org/openbravo/erpCommon/utility/ShowImage.java
src/org/openbravo/erpCommon/utility/ShowImageLogo.java
src/org/openbravo/erpCommon/utility/Utility.java
--- a/modules/org.openbravo.client.application/src/org/openbravo/client/application/window/ImagesActionHandler.java	Tue Jul 26 16:15:01 2011 +0200
+++ b/modules/org.openbravo.client.application/src/org/openbravo/client/application/window/ImagesActionHandler.java	Tue Jul 26 18:10:49 2011 +0200
@@ -18,12 +18,8 @@
  */
 package org.openbravo.client.application.window;
 
-import java.awt.image.BufferedImage;
-import java.io.ByteArrayInputStream;
 import java.util.Map;
 
-import javax.imageio.ImageIO;
-
 import org.apache.log4j.Logger;
 import org.codehaus.jettison.json.JSONObject;
 import org.openbravo.base.model.Entity;
@@ -32,6 +28,8 @@
 import org.openbravo.client.kernel.BaseActionHandler;
 import org.openbravo.dal.core.OBContext;
 import org.openbravo.dal.service.OBDal;
+import org.openbravo.erpCommon.utility.MimeTypeUtil;
+import org.openbravo.erpCommon.utility.Utility;
 import org.openbravo.model.ad.datamodel.Table;
 import org.openbravo.model.ad.ui.Tab;
 import org.openbravo.model.ad.utility.Image;
@@ -80,10 +78,25 @@
         OBContext.setAdminMode();
         String imageID = (String) parameters.get("inpimageId");
         Image image = OBDal.getInstance().get(Image.class, imageID);
-        ByteArrayInputStream bis = new ByteArrayInputStream(image.getBindaryData());
-        BufferedImage rImage = ImageIO.read(bis);
-        int width = rImage.getWidth();
-        int height = rImage.getHeight();
+        Long width;
+        Long height;
+        if (image.getHeight() == null || image.getWidth() == null) {
+          Long[] size = Utility.computeImageSize(image.getBindaryData());
+          width = size[0];
+          height = size[1];
+          image.setWidth(width);
+          image.setHeight(height);
+          OBDal.getInstance().save(image);
+          OBDal.getInstance().flush();
+        } else {
+          width = image.getWidth();
+          height = image.getHeight();
+        }
+        if (image.getMimetype() == null) {
+          image.setMimetype(MimeTypeUtil.getInstance().getMimeTypeName(image.getBindaryData()));
+          OBDal.getInstance().save(image);
+          OBDal.getInstance().flush();
+        }
         JSONObject obj = new JSONObject();
         obj.put("width", width);
         obj.put("height", height);
--- a/src-db/database/model/tables/AD_IMAGE.xml	Tue Jul 26 16:15:01 2011 +0200
+++ b/src-db/database/model/tables/AD_IMAGE.xml	Tue Jul 26 18:10:49 2011 +0200
@@ -45,6 +45,18 @@
         <default/>
         <onCreateDefault/>
       </column>
+      <column name="WIDTH" primaryKey="false" required="false" type="DECIMAL" size="10,0" autoIncrement="false">
+        <default/>
+        <onCreateDefault/>
+      </column>
+      <column name="HEIGHT" primaryKey="false" required="false" type="DECIMAL" size="10,0" autoIncrement="false">
+        <default/>
+        <onCreateDefault/>
+      </column>
+      <column name="MIMETYPE" primaryKey="false" required="false" type="VARCHAR" size="255" autoIncrement="false">
+        <default/>
+        <onCreateDefault/>
+      </column>
       <foreign-key foreignTable="AD_CLIENT" name="AD_IMAGE_AD_CLIENT">
         <reference local="AD_CLIENT_ID" foreign="AD_CLIENT_ID"/>
       </foreign-key>
--- a/src-db/database/sourcedata/AD_COLUMN.xml	Tue Jul 26 16:15:01 2011 +0200
+++ b/src-db/database/sourcedata/AD_COLUMN.xml	Tue Jul 26 18:10:49 2011 +0200
@@ -209029,6 +209029,37 @@
 <!--226F4EAA1F0311DEB6E25B68A38E8B87-->  <VALIDATEONNEW><![CDATA[Y]]></VALIDATEONNEW>
 <!--226F4EAA1F0311DEB6E25B68A38E8B87--></AD_COLUMN>
 
+<!--22F473081EF94CBA872065254DBC8950--><AD_COLUMN>
+<!--22F473081EF94CBA872065254DBC8950-->  <AD_COLUMN_ID><![CDATA[22F473081EF94CBA872065254DBC8950]]></AD_COLUMN_ID>
+<!--22F473081EF94CBA872065254DBC8950-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--22F473081EF94CBA872065254DBC8950-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--22F473081EF94CBA872065254DBC8950-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--22F473081EF94CBA872065254DBC8950-->  <NAME><![CDATA[Height]]></NAME>
+<!--22F473081EF94CBA872065254DBC8950-->  <COLUMNNAME><![CDATA[Height]]></COLUMNNAME>
+<!--22F473081EF94CBA872065254DBC8950-->  <AD_TABLE_ID><![CDATA[461]]></AD_TABLE_ID>
+<!--22F473081EF94CBA872065254DBC8950-->  <AD_REFERENCE_ID><![CDATA[11]]></AD_REFERENCE_ID>
+<!--22F473081EF94CBA872065254DBC8950-->  <FIELDLENGTH><![CDATA[12]]></FIELDLENGTH>
+<!--22F473081EF94CBA872065254DBC8950-->  <ISKEY><![CDATA[N]]></ISKEY>
+<!--22F473081EF94CBA872065254DBC8950-->  <ISPARENT><![CDATA[N]]></ISPARENT>
+<!--22F473081EF94CBA872065254DBC8950-->  <ISMANDATORY><![CDATA[N]]></ISMANDATORY>
+<!--22F473081EF94CBA872065254DBC8950-->  <ISUPDATEABLE><![CDATA[Y]]></ISUPDATEABLE>
+<!--22F473081EF94CBA872065254DBC8950-->  <ISIDENTIFIER><![CDATA[N]]></ISIDENTIFIER>
+<!--22F473081EF94CBA872065254DBC8950-->  <SEQNO><![CDATA[21]]></SEQNO>
+<!--22F473081EF94CBA872065254DBC8950-->  <ISTRANSLATED><![CDATA[N]]></ISTRANSLATED>
+<!--22F473081EF94CBA872065254DBC8950-->  <ISENCRYPTED><![CDATA[N]]></ISENCRYPTED>
+<!--22F473081EF94CBA872065254DBC8950-->  <ISSELECTIONCOLUMN><![CDATA[N]]></ISSELECTIONCOLUMN>
+<!--22F473081EF94CBA872065254DBC8950-->  <AD_ELEMENT_ID><![CDATA[13F4ADD5ED8E4FF2B039483283041FA5]]></AD_ELEMENT_ID>
+<!--22F473081EF94CBA872065254DBC8950-->  <ISSESSIONATTR><![CDATA[N]]></ISSESSIONATTR>
+<!--22F473081EF94CBA872065254DBC8950-->  <ISSECONDARYKEY><![CDATA[N]]></ISSECONDARYKEY>
+<!--22F473081EF94CBA872065254DBC8950-->  <ISDESENCRYPTABLE><![CDATA[N]]></ISDESENCRYPTABLE>
+<!--22F473081EF94CBA872065254DBC8950-->  <DEVELOPMENTSTATUS><![CDATA[RE]]></DEVELOPMENTSTATUS>
+<!--22F473081EF94CBA872065254DBC8950-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--22F473081EF94CBA872065254DBC8950-->  <POSITION><![CDATA[13]]></POSITION>
+<!--22F473081EF94CBA872065254DBC8950-->  <ISTRANSIENT><![CDATA[N]]></ISTRANSIENT>
+<!--22F473081EF94CBA872065254DBC8950-->  <ISAUTOSAVE><![CDATA[Y]]></ISAUTOSAVE>
+<!--22F473081EF94CBA872065254DBC8950-->  <VALIDATEONNEW><![CDATA[Y]]></VALIDATEONNEW>
+<!--22F473081EF94CBA872065254DBC8950--></AD_COLUMN>
+
 <!--238C42071A00420CB1D20768DA8CF37D--><AD_COLUMN>
 <!--238C42071A00420CB1D20768DA8CF37D-->  <AD_COLUMN_ID><![CDATA[238C42071A00420CB1D20768DA8CF37D]]></AD_COLUMN_ID>
 <!--238C42071A00420CB1D20768DA8CF37D-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -231788,6 +231819,37 @@
 <!--739A9DDF905A8F87E040007F010123C7-->  <VALIDATEONNEW><![CDATA[Y]]></VALIDATEONNEW>
 <!--739A9DDF905A8F87E040007F010123C7--></AD_COLUMN>
 
+<!--743916C18BFF4055A3DA351DD2F7F628--><AD_COLUMN>
+<!--743916C18BFF4055A3DA351DD2F7F628-->  <AD_COLUMN_ID><![CDATA[743916C18BFF4055A3DA351DD2F7F628]]></AD_COLUMN_ID>
+<!--743916C18BFF4055A3DA351DD2F7F628-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--743916C18BFF4055A3DA351DD2F7F628-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--743916C18BFF4055A3DA351DD2F7F628-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--743916C18BFF4055A3DA351DD2F7F628-->  <NAME><![CDATA[Width]]></NAME>
+<!--743916C18BFF4055A3DA351DD2F7F628-->  <COLUMNNAME><![CDATA[Width]]></COLUMNNAME>
+<!--743916C18BFF4055A3DA351DD2F7F628-->  <AD_TABLE_ID><![CDATA[461]]></AD_TABLE_ID>
+<!--743916C18BFF4055A3DA351DD2F7F628-->  <AD_REFERENCE_ID><![CDATA[11]]></AD_REFERENCE_ID>
+<!--743916C18BFF4055A3DA351DD2F7F628-->  <FIELDLENGTH><![CDATA[12]]></FIELDLENGTH>
+<!--743916C18BFF4055A3DA351DD2F7F628-->  <ISKEY><![CDATA[N]]></ISKEY>
+<!--743916C18BFF4055A3DA351DD2F7F628-->  <ISPARENT><![CDATA[N]]></ISPARENT>
+<!--743916C18BFF4055A3DA351DD2F7F628-->  <ISMANDATORY><![CDATA[N]]></ISMANDATORY>
+<!--743916C18BFF4055A3DA351DD2F7F628-->  <ISUPDATEABLE><![CDATA[Y]]></ISUPDATEABLE>
+<!--743916C18BFF4055A3DA351DD2F7F628-->  <ISIDENTIFIER><![CDATA[N]]></ISIDENTIFIER>
+<!--743916C18BFF4055A3DA351DD2F7F628-->  <SEQNO><![CDATA[11]]></SEQNO>
+<!--743916C18BFF4055A3DA351DD2F7F628-->  <ISTRANSLATED><![CDATA[N]]></ISTRANSLATED>
+<!--743916C18BFF4055A3DA351DD2F7F628-->  <ISENCRYPTED><![CDATA[N]]></ISENCRYPTED>
+<!--743916C18BFF4055A3DA351DD2F7F628-->  <ISSELECTIONCOLUMN><![CDATA[N]]></ISSELECTIONCOLUMN>
+<!--743916C18BFF4055A3DA351DD2F7F628-->  <AD_ELEMENT_ID><![CDATA[3AB8D15AD3E644B7A02B568936DCFE81]]></AD_ELEMENT_ID>
+<!--743916C18BFF4055A3DA351DD2F7F628-->  <ISSESSIONATTR><![CDATA[N]]></ISSESSIONATTR>
+<!--743916C18BFF4055A3DA351DD2F7F628-->  <ISSECONDARYKEY><![CDATA[N]]></ISSECONDARYKEY>
+<!--743916C18BFF4055A3DA351DD2F7F628-->  <ISDESENCRYPTABLE><![CDATA[N]]></ISDESENCRYPTABLE>
+<!--743916C18BFF4055A3DA351DD2F7F628-->  <DEVELOPMENTSTATUS><![CDATA[RE]]></DEVELOPMENTSTATUS>
+<!--743916C18BFF4055A3DA351DD2F7F628-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--743916C18BFF4055A3DA351DD2F7F628-->  <POSITION><![CDATA[12]]></POSITION>
+<!--743916C18BFF4055A3DA351DD2F7F628-->  <ISTRANSIENT><![CDATA[N]]></ISTRANSIENT>
+<!--743916C18BFF4055A3DA351DD2F7F628-->  <ISAUTOSAVE><![CDATA[Y]]></ISAUTOSAVE>
+<!--743916C18BFF4055A3DA351DD2F7F628-->  <VALIDATEONNEW><![CDATA[Y]]></VALIDATEONNEW>
+<!--743916C18BFF4055A3DA351DD2F7F628--></AD_COLUMN>
+
 <!--744D56EC1783443EA8499498121C551A--><AD_COLUMN>
 <!--744D56EC1783443EA8499498121C551A-->  <AD_COLUMN_ID><![CDATA[744D56EC1783443EA8499498121C551A]]></AD_COLUMN_ID>
 <!--744D56EC1783443EA8499498121C551A-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -258676,6 +258738,37 @@
 <!--D436A87CCB6611DDBF757B72CD9436D9-->  <VALIDATEONNEW><![CDATA[Y]]></VALIDATEONNEW>
 <!--D436A87CCB6611DDBF757B72CD9436D9--></AD_COLUMN>
 
+<!--D44EC8E368A74AEA8AD7EFF13B1FBA6A--><AD_COLUMN>
+<!--D44EC8E368A74AEA8AD7EFF13B1FBA6A-->  <AD_COLUMN_ID><![CDATA[D44EC8E368A74AEA8AD7EFF13B1FBA6A]]></AD_COLUMN_ID>
+<!--D44EC8E368A74AEA8AD7EFF13B1FBA6A-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--D44EC8E368A74AEA8AD7EFF13B1FBA6A-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--D44EC8E368A74AEA8AD7EFF13B1FBA6A-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--D44EC8E368A74AEA8AD7EFF13B1FBA6A-->  <NAME><![CDATA[Mimetype]]></NAME>
+<!--D44EC8E368A74AEA8AD7EFF13B1FBA6A-->  <COLUMNNAME><![CDATA[Mimetype]]></COLUMNNAME>
+<!--D44EC8E368A74AEA8AD7EFF13B1FBA6A-->  <AD_TABLE_ID><![CDATA[461]]></AD_TABLE_ID>
+<!--D44EC8E368A74AEA8AD7EFF13B1FBA6A-->  <AD_REFERENCE_ID><![CDATA[10]]></AD_REFERENCE_ID>
+<!--D44EC8E368A74AEA8AD7EFF13B1FBA6A-->  <FIELDLENGTH><![CDATA[255]]></FIELDLENGTH>
+<!--D44EC8E368A74AEA8AD7EFF13B1FBA6A-->  <ISKEY><![CDATA[N]]></ISKEY>
+<!--D44EC8E368A74AEA8AD7EFF13B1FBA6A-->  <ISPARENT><![CDATA[N]]></ISPARENT>
+<!--D44EC8E368A74AEA8AD7EFF13B1FBA6A-->  <ISMANDATORY><![CDATA[N]]></ISMANDATORY>
+<!--D44EC8E368A74AEA8AD7EFF13B1FBA6A-->  <ISUPDATEABLE><![CDATA[Y]]></ISUPDATEABLE>
+<!--D44EC8E368A74AEA8AD7EFF13B1FBA6A-->  <ISIDENTIFIER><![CDATA[N]]></ISIDENTIFIER>
+<!--D44EC8E368A74AEA8AD7EFF13B1FBA6A-->  <SEQNO><![CDATA[31]]></SEQNO>
+<!--D44EC8E368A74AEA8AD7EFF13B1FBA6A-->  <ISTRANSLATED><![CDATA[N]]></ISTRANSLATED>
+<!--D44EC8E368A74AEA8AD7EFF13B1FBA6A-->  <ISENCRYPTED><![CDATA[N]]></ISENCRYPTED>
+<!--D44EC8E368A74AEA8AD7EFF13B1FBA6A-->  <ISSELECTIONCOLUMN><![CDATA[N]]></ISSELECTIONCOLUMN>
+<!--D44EC8E368A74AEA8AD7EFF13B1FBA6A-->  <AD_ELEMENT_ID><![CDATA[8971717F183347B0834A2AEB218C5AFB]]></AD_ELEMENT_ID>
+<!--D44EC8E368A74AEA8AD7EFF13B1FBA6A-->  <ISSESSIONATTR><![CDATA[N]]></ISSESSIONATTR>
+<!--D44EC8E368A74AEA8AD7EFF13B1FBA6A-->  <ISSECONDARYKEY><![CDATA[N]]></ISSECONDARYKEY>
+<!--D44EC8E368A74AEA8AD7EFF13B1FBA6A-->  <ISDESENCRYPTABLE><![CDATA[N]]></ISDESENCRYPTABLE>
+<!--D44EC8E368A74AEA8AD7EFF13B1FBA6A-->  <DEVELOPMENTSTATUS><![CDATA[RE]]></DEVELOPMENTSTATUS>
+<!--D44EC8E368A74AEA8AD7EFF13B1FBA6A-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--D44EC8E368A74AEA8AD7EFF13B1FBA6A-->  <POSITION><![CDATA[14]]></POSITION>
+<!--D44EC8E368A74AEA8AD7EFF13B1FBA6A-->  <ISTRANSIENT><![CDATA[N]]></ISTRANSIENT>
+<!--D44EC8E368A74AEA8AD7EFF13B1FBA6A-->  <ISAUTOSAVE><![CDATA[Y]]></ISAUTOSAVE>
+<!--D44EC8E368A74AEA8AD7EFF13B1FBA6A-->  <VALIDATEONNEW><![CDATA[Y]]></VALIDATEONNEW>
+<!--D44EC8E368A74AEA8AD7EFF13B1FBA6A--></AD_COLUMN>
+
 <!--D463F52ACB6611DD87FACF0742499ECD--><AD_COLUMN>
 <!--D463F52ACB6611DD87FACF0742499ECD-->  <AD_COLUMN_ID><![CDATA[D463F52ACB6611DD87FACF0742499ECD]]></AD_COLUMN_ID>
 <!--D463F52ACB6611DD87FACF0742499ECD-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
--- a/src-db/database/sourcedata/AD_ELEMENT.xml	Tue Jul 26 16:15:01 2011 +0200
+++ b/src-db/database/sourcedata/AD_ELEMENT.xml	Tue Jul 26 18:10:49 2011 +0200
@@ -19172,6 +19172,17 @@
 <!--0DCA4840773E45198061B6F1E5F22841-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
 <!--0DCA4840773E45198061B6F1E5F22841--></AD_ELEMENT>
 
+<!--13F4ADD5ED8E4FF2B039483283041FA5--><AD_ELEMENT>
+<!--13F4ADD5ED8E4FF2B039483283041FA5-->  <AD_ELEMENT_ID><![CDATA[13F4ADD5ED8E4FF2B039483283041FA5]]></AD_ELEMENT_ID>
+<!--13F4ADD5ED8E4FF2B039483283041FA5-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--13F4ADD5ED8E4FF2B039483283041FA5-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--13F4ADD5ED8E4FF2B039483283041FA5-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--13F4ADD5ED8E4FF2B039483283041FA5-->  <COLUMNNAME><![CDATA[Height]]></COLUMNNAME>
+<!--13F4ADD5ED8E4FF2B039483283041FA5-->  <NAME><![CDATA[Height]]></NAME>
+<!--13F4ADD5ED8E4FF2B039483283041FA5-->  <PRINTNAME><![CDATA[Height]]></PRINTNAME>
+<!--13F4ADD5ED8E4FF2B039483283041FA5-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--13F4ADD5ED8E4FF2B039483283041FA5--></AD_ELEMENT>
+
 <!--14976679CF0542CDA192111320E142C5--><AD_ELEMENT>
 <!--14976679CF0542CDA192111320E142C5-->  <AD_ELEMENT_ID><![CDATA[14976679CF0542CDA192111320E142C5]]></AD_ELEMENT_ID>
 <!--14976679CF0542CDA192111320E142C5-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -19361,6 +19372,17 @@
 <!--3A29545A247A41CBB6ED3B5AA0CBF7CC-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
 <!--3A29545A247A41CBB6ED3B5AA0CBF7CC--></AD_ELEMENT>
 
+<!--3AB8D15AD3E644B7A02B568936DCFE81--><AD_ELEMENT>
+<!--3AB8D15AD3E644B7A02B568936DCFE81-->  <AD_ELEMENT_ID><![CDATA[3AB8D15AD3E644B7A02B568936DCFE81]]></AD_ELEMENT_ID>
+<!--3AB8D15AD3E644B7A02B568936DCFE81-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--3AB8D15AD3E644B7A02B568936DCFE81-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--3AB8D15AD3E644B7A02B568936DCFE81-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--3AB8D15AD3E644B7A02B568936DCFE81-->  <COLUMNNAME><![CDATA[Width]]></COLUMNNAME>
+<!--3AB8D15AD3E644B7A02B568936DCFE81-->  <NAME><![CDATA[Width]]></NAME>
+<!--3AB8D15AD3E644B7A02B568936DCFE81-->  <PRINTNAME><![CDATA[Width]]></PRINTNAME>
+<!--3AB8D15AD3E644B7A02B568936DCFE81-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--3AB8D15AD3E644B7A02B568936DCFE81--></AD_ELEMENT>
+
 <!--3B584D993CCF41B698DBE642AFC21AE4--><AD_ELEMENT>
 <!--3B584D993CCF41B698DBE642AFC21AE4-->  <AD_ELEMENT_ID><![CDATA[3B584D993CCF41B698DBE642AFC21AE4]]></AD_ELEMENT_ID>
 <!--3B584D993CCF41B698DBE642AFC21AE4-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -23938,6 +23960,17 @@
 <!--877E302527991536E040007F010060E9-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
 <!--877E302527991536E040007F010060E9--></AD_ELEMENT>
 
+<!--8971717F183347B0834A2AEB218C5AFB--><AD_ELEMENT>
+<!--8971717F183347B0834A2AEB218C5AFB-->  <AD_ELEMENT_ID><![CDATA[8971717F183347B0834A2AEB218C5AFB]]></AD_ELEMENT_ID>
+<!--8971717F183347B0834A2AEB218C5AFB-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--8971717F183347B0834A2AEB218C5AFB-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--8971717F183347B0834A2AEB218C5AFB-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--8971717F183347B0834A2AEB218C5AFB-->  <COLUMNNAME><![CDATA[Mimetype]]></COLUMNNAME>
+<!--8971717F183347B0834A2AEB218C5AFB-->  <NAME><![CDATA[Mimetype]]></NAME>
+<!--8971717F183347B0834A2AEB218C5AFB-->  <PRINTNAME><![CDATA[Mimetype]]></PRINTNAME>
+<!--8971717F183347B0834A2AEB218C5AFB-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--8971717F183347B0834A2AEB218C5AFB--></AD_ELEMENT>
+
 <!--8A19431CC0E020DBE040007F01013CCA--><AD_ELEMENT>
 <!--8A19431CC0E020DBE040007F01013CCA-->  <AD_ELEMENT_ID><![CDATA[8A19431CC0E020DBE040007F01013CCA]]></AD_ELEMENT_ID>
 <!--8A19431CC0E020DBE040007F01013CCA-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
--- a/src/org/openbravo/erpCommon/info/ImageInfoBLOB.java	Tue Jul 26 16:15:01 2011 +0200
+++ b/src/org/openbravo/erpCommon/info/ImageInfoBLOB.java	Tue Jul 26 18:10:49 2011 +0200
@@ -37,6 +37,8 @@
 import org.openbravo.dal.core.OBContext;
 import org.openbravo.dal.service.OBDal;
 import org.openbravo.data.Sqlc;
+import org.openbravo.erpCommon.utility.MimeTypeUtil;
+import org.openbravo.erpCommon.utility.Utility;
 import org.openbravo.model.ad.datamodel.Column;
 import org.openbravo.model.ad.datamodel.Table;
 import org.openbravo.model.ad.ui.Tab;
@@ -111,7 +113,8 @@
       try {
         final FileItem fi = vars.getMultiFile("inpFile");
         byte[] bytea = fi.get();
-
+        Long[] size = Utility.computeImageSize(bytea);
+        String mimeType = MimeTypeUtil.getInstance().getMimeTypeName(bytea);
         // Using DAL to write the image data to the database
         Image image;
         if (imageID == null || imageID.equals("")) {
@@ -121,6 +124,9 @@
           image.setBindaryData(bytea);
           image.setActive(true);
           image.setName("Image");
+          image.setWidth(size[0]);
+          image.setHeight(size[1]);
+          image.setMimetype(mimeType);
           OBDal.getInstance().save(image);
           OBDal.getInstance().flush();
 
@@ -128,6 +134,9 @@
           image = OBDal.getInstance().get(Image.class, imageID);
           image.setActive(true);
           image.setBindaryData(bytea);
+          image.setWidth(size[0]);
+          image.setHeight(size[1]);
+          image.setMimetype(mimeType);
           OBDal.getInstance().flush();
         }
         response.setContentType("text/html; charset=UTF-8");
--- a/src/org/openbravo/erpCommon/utility/ImageToDatabaseLoader.java	Tue Jul 26 16:15:01 2011 +0200
+++ b/src/org/openbravo/erpCommon/utility/ImageToDatabaseLoader.java	Tue Jul 26 18:10:49 2011 +0200
@@ -42,6 +42,10 @@
           }
           Image image = OBProvider.getInstance().get(Image.class);
           image.setBindaryData(bytes);
+          image.setMimetype(MimeTypeUtil.getInstance().getMimeTypeName(bytes));
+          Long[] size = Utility.computeImageSize(bytes);
+          image.setWidth(size[0]);
+          image.setHeight(size[1]);
           image.setName("Image");
           getLog().info("Inserting image with property: " + properties[i]);
           OBDal.getInstance().save(image);
--- a/src/org/openbravo/erpCommon/utility/ShowImage.java	Tue Jul 26 16:15:01 2011 +0200
+++ b/src/org/openbravo/erpCommon/utility/ShowImage.java	Tue Jul 26 18:10:49 2011 +0200
@@ -29,6 +29,8 @@
 
 import org.openbravo.base.secureApp.HttpSecureAppServlet;
 import org.openbravo.base.secureApp.VariablesSecureApp;
+import org.openbravo.dal.service.OBDal;
+import org.openbravo.model.ad.utility.Image;
 
 /**
  * 
@@ -58,7 +60,17 @@
     byte[] img = Utility.getImage(id);
 
     // write the mimetype
-    final String mimeType = MimeTypeUtil.getInstance().getMimeTypeName(img);
+    Image image = OBDal.getInstance().get(Image.class, id);
+    final String mimeType;
+    if (image.getMimetype() != null) {
+      mimeType = image.getMimetype();
+    } else {
+      mimeType = MimeTypeUtil.getInstance().getMimeTypeName(img);
+      image.setMimetype(mimeType);
+      OBDal.getInstance().save(image);
+      OBDal.getInstance().flush();
+    }
+
     if (!mimeType.equals("")) {
       response.setContentType(mimeType);
     }
--- a/src/org/openbravo/erpCommon/utility/ShowImageLogo.java	Tue Jul 26 16:15:01 2011 +0200
+++ b/src/org/openbravo/erpCommon/utility/ShowImageLogo.java	Tue Jul 26 18:10:49 2011 +0200
@@ -28,6 +28,8 @@
 
 import org.openbravo.base.HttpBaseServlet;
 import org.openbravo.base.secureApp.VariablesSecureApp;
+import org.openbravo.dal.service.OBDal;
+import org.openbravo.model.ad.utility.Image;
 
 /**
  * 
@@ -50,10 +52,24 @@
     String org = vars.getStringParameter("orgId");
 
     // read the image data
-    byte[] img = Utility.getImageLogo(logo, org);
-
+    byte[] img;
+    String mimeType = null;
+    Image image = Utility.getImageLogoObject(logo, org);
+    if (image != null) {
+      img = image.getBindaryData();
+      mimeType = image.getMimetype();
+    } else {
+      img = Utility.getImageLogo(logo, org);
+    }
     // write the mimetype
-    final String mimeType = MimeTypeUtil.getInstance().getMimeTypeName(img);
+    if (mimeType == null) {
+      mimeType = MimeTypeUtil.getInstance().getMimeTypeName(img);
+      if (image != null) {
+        image.setMimetype(mimeType);
+        OBDal.getInstance().save(image);
+        OBDal.getInstance().flush();
+      }
+    }
     if (!mimeType.equals("")) {
       response.setContentType(mimeType);
     }
--- a/src/org/openbravo/erpCommon/utility/Utility.java	Tue Jul 26 16:15:01 2011 +0200
+++ b/src/org/openbravo/erpCommon/utility/Utility.java	Tue Jul 26 18:10:49 2011 +0200
@@ -2380,7 +2380,7 @@
     try {
       ByteArrayOutputStream bout = new ByteArrayOutputStream();
       new FileUtility(OBConfigFileProvider.getInstance().getServletContext().getRealPath("/"),
-          "web/images/blank.gif", false, true).dumpFile(bout);
+          getDefaultImageLogo("Empty"), false, true).dumpFile(bout);
       bout.close();
       return bout.toByteArray();
     } catch (IOException ex) {
@@ -2400,21 +2400,43 @@
    */
   public static byte[] getImage(String id) {
 
-    OBContext.setAdminMode();
+    byte[] imageByte;
     try {
-      Image img = OBDal.getInstance().get(Image.class, id);
+      Image img = getImageObject(id);
       if (img == null) {
         log4j.error("Image does not exist: " + id);
-        return getBlankImage();
+        imageByte = getBlankImage();
       } else {
-        return img.getBindaryData();
+        imageByte = img.getBindaryData();
       }
     } catch (Exception e) {
       log4j.error("Could not load image from database: " + id, e);
-      return getBlankImage();
+      imageByte = getBlankImage();
+    }
+
+    return imageByte;
+  }
+
+  /**
+   * Provides the image as an image object. These images are stored in the table AD_IMAGES as a BLOB
+   * field.
+   * 
+   * @param id
+   *          The id of the image to display
+   * @return The image requested
+   * @see #getImage(String)
+   */
+  public static Image getImageObject(String id) {
+    Image img = null;
+    OBContext.setAdminMode();
+    try {
+      img = OBDal.getInstance().get(Image.class, id);
+    } catch (Exception e) {
+      log4j.error("Could not load image from database: " + id, e);
     } finally {
       OBContext.restorePreviousMode();
     }
+    return img;
   }
 
   /**
@@ -2430,19 +2452,6 @@
     return ImageIO.read(new ByteArrayInputStream(getImage(id)));
   }
 
-  private static byte[] defaultImageLogo(Image img, String path) throws IOException {
-
-    if (img == null) {
-      ByteArrayOutputStream bout = new ByteArrayOutputStream();
-      new FileUtility(OBConfigFileProvider.getInstance().getServletContext().getRealPath("/"),
-          path, false, true).dumpFile(bout);
-      bout.close();
-      return bout.toByteArray();
-    } else {
-      return img.getBindaryData();
-    }
-  }
-
   /**
    * Provides the image logo as a byte array for the indicated parameters.
    * 
@@ -2454,18 +2463,15 @@
    *          logo you can indicate the organization used to request the logo.
    * @return The image requested
    */
-  public static byte[] getImageLogo(String logo, String org) {
-
+  public static Image getImageLogoObject(String logo, String org) {
+    Image img = null;
     OBContext.setAdminMode();
     try {
-      Image img = null;
 
       if ("yourcompanylogin".equals(logo)) {
         img = OBDal.getInstance().get(SystemInformation.class, "0").getYourCompanyLoginImage();
-        return defaultImageLogo(img, "web/images/CompanyLogo_big.png");
       } else if ("youritservicelogin".equals(logo)) {
         img = OBDal.getInstance().get(SystemInformation.class, "0").getYourItServiceLoginImage();
-        return defaultImageLogo(img, "web/images/SupportLogo_big.png");
       } else if ("yourcompanymenu".equals(logo)) {
         img = OBDal.getInstance()
             .get(ClientInformation.class, OBContext.getOBContext().getCurrentClient().getId())
@@ -2473,7 +2479,6 @@
         if (img == null) {
           img = OBDal.getInstance().get(SystemInformation.class, "0").getYourCompanyMenuImage();
         }
-        return defaultImageLogo(img, "web/images/CompanyLogo_small.png");
       } else if ("yourcompanybig".equals(logo)) {
         img = OBDal.getInstance()
             .get(ClientInformation.class, OBContext.getOBContext().getCurrentClient().getId())
@@ -2481,7 +2486,6 @@
         if (img == null) {
           img = OBDal.getInstance().get(SystemInformation.class, "0").getYourCompanyBigImage();
         }
-        return defaultImageLogo(img, "web/skins/ltr/Default/Login/initialOpenbravoLogo.png");
       } else if ("yourcompanydoc".equals(logo)) {
         if (org != null && !org.equals("")) {
           Organization organization = OBDal.getInstance().get(Organization.class, org);
@@ -2490,10 +2494,8 @@
         if (img == null) {
           img = OBDal.getInstance().get(SystemInformation.class, "0").getYourCompanyDocumentImage();
         }
-        return defaultImageLogo(img, "web/images/CompanyLogo_big.png");
       } else if ("banner-production".equals(logo)) {
         img = OBDal.getInstance().get(SystemInformation.class, "0").getProductionBannerImage();
-        return defaultImageLogo(img, "web/images/blank.gif");
       } else if ("yourcompanylegal".equals(logo)) {
         if (org != null && !org.equals("")) {
           Organization organization = OBDal.getInstance().get(Organization.class, org);
@@ -2510,17 +2512,106 @@
                 .getYourCompanyDocumentImage();
           }
         }
-        return defaultImageLogo(img, "web/images/CompanyLogo_big.png");
       } else {
         log4j.error("Logo key does not exist: " + logo);
-        return getBlankImage();
       }
     } catch (Exception e) {
       log4j.error("Could not load logo from database: " + logo + ", " + org, e);
-      return getBlankImage();
     } finally {
       OBContext.restorePreviousMode();
     }
+    return img;
+  }
+
+  /**
+   * Provides the image logo as a byte array for the indicated parameters.
+   * 
+   * @param logo
+   *          The name of the logo to display This can be one of the following: yourcompanylogin,
+   *          youritservicelogin, yourcompanymenu, yourcompanybig or yourcompanydoc
+   * @param org
+   *          The organization id used to get the logo In the case of requesting the yourcompanydoc
+   *          logo you can indicate the organization used to request the logo.
+   * @return The image requested
+   */
+  public static byte[] getImageLogo(String logo, String org) {
+
+    byte[] imageByte;
+
+    try {
+      Image img = getImageLogoObject(logo, org);
+      if (img == null) {
+        String path = getDefaultImageLogo(logo);
+        ByteArrayOutputStream bout = new ByteArrayOutputStream();
+        new FileUtility(OBConfigFileProvider.getInstance().getServletContext().getRealPath("/"),
+            path, false, true).dumpFile(bout);
+        bout.close();
+        imageByte = bout.toByteArray();
+      } else {
+        imageByte = img.getBindaryData();
+      }
+
+    } catch (Exception e) {
+      log4j.error("Could not load logo from database: " + logo + ", " + org, e);
+      imageByte = getBlankImage();
+    }
+    return imageByte;
+  }
+
+  /**
+   * Provides the image logo as a byte array for the indicated parameters.
+   * 
+   * @param logo
+   *          The name of the logo to display This can be one of the following: yourcompanylogin,
+   *          youritservicelogin, yourcompanymenu, yourcompanybig or yourcompanydoc
+   * @param org
+   *          The organization id used to get the logo In the case of requesting the yourcompanydoc
+   *          logo you can indicate the organization used to request the logo.
+   * @return The image requested
+   */
+  public static String getDefaultImageLogo(String logo) {
+
+    String defaultImagePath = null;
+
+    if (logo == null) {
+      defaultImagePath = "web/images/blank.gif";
+    } else if ("yourcompanylogin".equals(logo)) {
+      defaultImagePath = "web/images/CompanyLogo_big.png";
+    } else if ("youritservicelogin".equals(logo)) {
+      defaultImagePath = "web/images/SupportLogo_big.png";
+    } else if ("yourcompanymenu".equals(logo)) {
+      defaultImagePath = "web/images/CompanyLogo_small.png";
+    } else if ("yourcompanybig".equals(logo)) {
+      defaultImagePath = "web/skins/ltr/Default/Login/initialOpenbravoLogo.png";
+    } else if ("yourcompanydoc".equals(logo)) {
+      defaultImagePath = "web/images/CompanyLogo_big.png";
+    } else if ("banner-production".equals(logo)) {
+      defaultImagePath = "web/images/blank.gif";
+    } else if ("yourcompanylegal".equals(logo)) {
+      defaultImagePath = "web/images/CompanyLogo_big.png";
+    } else {
+      defaultImagePath = "web/images/blank.gif";
+    }
+
+    return defaultImagePath;
+
+  }
+
+  /**
+   * This method calculates the size of an image
+   * 
+   * @param bytea
+   *          The contents of the image
+   * @return An Long array with two elements (width, height)
+   * @throws IOException
+   */
+  public static Long[] computeImageSize(byte[] bytea) throws IOException {
+    ByteArrayInputStream bis = new ByteArrayInputStream(bytea);
+    BufferedImage rImage = ImageIO.read(bis);
+    Long[] size = new Long[2];
+    size[0] = new Long(rImage.getWidth());
+    size[1] = new Long(rImage.getHeight());
+    return size;
   }
 
   /**