Ignore:
Timestamp:
Sep 1, 2010, 6:48:53 PM (14 years ago)
Author:
mlg
Message:

Bug correction :
bug:0001837 : there is now a default translation file (in english), so the application won't crash when a translation is not found
bug:0001833 : the accents are manage when creating a new category
bug:0001832 : on a right click on the categories list, the selection is now visible
bug:0001830 : there is no bug on refreshing the categories tree

Features :
feature:001828 : exif and iptc tags are kept after resizing an image
feature:001827 : pwg.images.addChunk is now fully used : images are split into chunks before being sent

Other features :

  • The user can manage his preferences :

-The web images size
-The chunks size

  • The user can save the login informations (url, login, password) /!\ in a plain text file !
File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/jiwigo/trunk/src/main/java/fr/mael/jiwigo/transverse/util/Outil.java

    r6821 r6831  
    22
    33import java.io.BufferedInputStream;
     4import java.io.ByteArrayInputStream;
     5import java.io.ByteArrayOutputStream;
    46import java.io.DataInputStream;
    57import java.io.File;
    68import java.io.FileInputStream;
     9import java.io.FileOutputStream;
    710import java.io.IOException;
    811import java.io.InputStream;
     
    1417import java.net.URLClassLoader;
    1518import java.security.MessageDigest;
    16 
     19import java.util.ArrayList;
     20
     21import org.apache.sanselan.Sanselan;
     22import org.apache.sanselan.common.IImageMetadata;
     23import org.apache.sanselan.formats.jpeg.JpegImageMetadata;
     24import org.apache.sanselan.formats.jpeg.JpegPhotoshopMetadata;
     25import org.apache.sanselan.formats.jpeg.exifRewrite.ExifRewriter;
     26import org.apache.sanselan.formats.jpeg.iptc.JpegIptcRewriter;
     27import org.apache.sanselan.formats.jpeg.iptc.PhotoshopApp13Data;
     28import org.apache.sanselan.formats.tiff.write.TiffOutputSet;
    1729import org.jdom.Document;
    1830import org.jdom.JDOMException;
     
    209221        return result.toString();
    210222    }
     223
     224    /**
     225     * Function that splits a file
     226     * @param fichier the file to split
     227     * @param size the size of the resulting chunks
     228     * @return the list of files
     229     * @throws IOException
     230     */
     231    //feature:0001827
     232    public static ArrayList<File> splitFile(File fichier, int size) throws IOException {
     233        FileInputStream fis = new FileInputStream(fichier);
     234        byte buffer[] = new byte[size];
     235        ArrayList<File> listFichiers = new ArrayList<File>();
     236        int count = 0;
     237        while (true) {
     238            int i = fis.read(buffer, 0, size);
     239            if (i == -1)
     240                break;
     241            File file = new File(System.getProperty("java.io.tmpdir") + "/tempcut" + count);
     242            listFichiers.add(file);
     243            FileOutputStream fos = new FileOutputStream(file);
     244            fos.write(buffer, 0, i);
     245            fos.flush();
     246            fos.close();
     247
     248            ++count;
     249        }
     250        return listFichiers;
     251    }
     252
     253    /**
     254     * Function used to put the exif and iptc metadata from one image to another
     255     * @param enriched original image where the metadata comes from
     256     * @param naked image where to put metadata
     257     * @return enriched image
     258     * @throws Exception
     259     */
     260    public static byte[] enrich(byte[] enriched, byte[] naked) throws Exception {
     261
     262        // read IPTC metadata from the original enriched image
     263        IImageMetadata metadata = Sanselan.getMetadata(enriched);
     264        JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata;
     265        JpegPhotoshopMetadata photoshopMetadata = jpegMetadata.getPhotoshop();
     266        if (photoshopMetadata == null) {
     267            return naked;
     268        }
     269
     270        PhotoshopApp13Data data = photoshopMetadata.photoshopApp13Data;
     271
     272        // read the EXIF metadata from the parsed JPEG metadata
     273        TiffOutputSet outputSet = jpegMetadata.getExif().getOutputSet();
     274
     275        // enrich the naked byte[] with EXIF metadata
     276        ExifRewriter writer = new ExifRewriter();
     277        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
     278        writer.updateExifMetadataLossless(naked, outputStream, outputSet);
     279
     280        // enrich the partially clothed byte[] with IPTC metadata
     281        InputStream src = new ByteArrayInputStream(outputStream.toByteArray());
     282        ByteArrayOutputStream dest = new ByteArrayOutputStream();
     283        new JpegIptcRewriter().writeIPTC(src, dest, data);
     284
     285        // return the fully clothed image as a byte[]
     286        return dest.toByteArray();
     287    }
     288
     289    public static void byteToFile(String fichier, byte[] bytes) throws IOException {
     290        FileOutputStream fos = new FileOutputStream(fichier);
     291        fos.write(bytes);
     292        fos.flush();
     293        fos.close();
     294
     295    }
    211296}
Note: See TracChangeset for help on using the changeset viewer.