Search in sources :

Example 1 with ByteSourceFile

use of org.apache.commons.imaging.common.bytesource.ByteSourceFile in project commons-imaging by apache.

the class ExifRewriter method updateExifMetadataLossy.

/**
 * Reads a Jpeg image, replaces the EXIF metadata and writes the result to a
 * stream.
 *
 * <p>Note that this uses the "Lossy" approach - the algorithm overwrites the
 * entire EXIF segment, ignoring the possibility that it may be discarding
 * data it couldn't parse (such as Maker Notes).</p>
 *
 * @param src
 *            Image file.
 * @param os
 *            OutputStream to write the image to.
 * @param outputSet
 *            TiffOutputSet containing the EXIF data to write.
 * @throws ImageReadException if it fails to read the JFIF segments
 * @throws IOException if it fails to read the image data
 * @throws ImageWriteException if it fails to write the updated data
 */
public void updateExifMetadataLossy(final File src, final OutputStream os, final TiffOutputSet outputSet) throws ImageReadException, IOException, ImageWriteException {
    final ByteSource byteSource = new ByteSourceFile(src);
    updateExifMetadataLossy(byteSource, os, outputSet);
}
Also used : ByteSource(org.apache.commons.imaging.common.bytesource.ByteSource) ByteSourceFile(org.apache.commons.imaging.common.bytesource.ByteSourceFile)

Example 2 with ByteSourceFile

use of org.apache.commons.imaging.common.bytesource.ByteSourceFile in project commons-imaging by apache.

the class ExifRewriter method updateExifMetadataLossless.

/**
 * Reads a Jpeg image, replaces the EXIF metadata and writes the result to a
 * stream.
 *
 * <p>Note that this uses the "Lossless" approach - in order to preserve data
 * embedded in the EXIF segment that it can't parse (such as Maker Notes),
 * this algorithm avoids overwriting any part of the original segment that
 * it couldn't parse. This can cause the EXIF segment to grow with each
 * update, which is a serious issue, since all EXIF data must fit in a
 * single APP1 segment of the Jpeg image.</p>
 *
 * @param src
 *            Image file.
 * @param os
 *            OutputStream to write the image to.
 * @param outputSet
 *            TiffOutputSet containing the EXIF data to write.
 * @throws ImageReadException if it fails to read the JFIF segments
 * @throws IOException if it fails to read the image data
 * @throws ImageWriteException if it fails to write the updated data
 */
public void updateExifMetadataLossless(final File src, final OutputStream os, final TiffOutputSet outputSet) throws ImageReadException, IOException, ImageWriteException {
    final ByteSource byteSource = new ByteSourceFile(src);
    updateExifMetadataLossless(byteSource, os, outputSet);
}
Also used : ByteSource(org.apache.commons.imaging.common.bytesource.ByteSource) ByteSourceFile(org.apache.commons.imaging.common.bytesource.ByteSourceFile)

Example 3 with ByteSourceFile

use of org.apache.commons.imaging.common.bytesource.ByteSourceFile in project commons-imaging by apache.

the class JpegXmpRewriter method updateXmpXml.

/**
 * Reads a Jpeg image, replaces the XMP XML and writes the result to a
 * stream.
 *
 * @param src
 *            Image file.
 * @param os
 *            OutputStream to write the image to.
 * @param xmpXml
 *            String containing XMP XML.
 * @throws ImageReadException if it fails to read the JFIF segments
 * @throws IOException if it fails to read or write the data from the segments
 * @throws ImageWriteException if it fails to write the JFIF segments
 */
public void updateXmpXml(final File src, final OutputStream os, final String xmpXml) throws ImageReadException, IOException, ImageWriteException {
    final ByteSource byteSource = new ByteSourceFile(src);
    updateXmpXml(byteSource, os, xmpXml);
}
Also used : ByteSource(org.apache.commons.imaging.common.bytesource.ByteSource) ByteSourceFile(org.apache.commons.imaging.common.bytesource.ByteSourceFile)

Example 4 with ByteSourceFile

use of org.apache.commons.imaging.common.bytesource.ByteSourceFile in project commons-imaging by apache.

the class JpegIptcRewriter method removeIPTC.

/**
 * Reads a Jpeg image, removes all IPTC data from the App13 segment but
 * leaves the other data in that segment (if present) unchanged (unless
 * removeSegment is true) and writes the result to a stream.
 * <p>
 *
 * @param src
 *            Image file.
 * @param os
 *            OutputStream to write the image to.
 * @param removeSegment
 *            Remove the App13 segment.
 *
 * @see java.io.File
 * @see java.io.OutputStream
 * @throws ImageReadException if there are more than one Photoshop App13 segment, or if
 *         the Photoshop segment cannot be parsed
 * @throws IOException if it fails to read from the origin byte source, or to write to the
 *         target byte source
 * @throws ImageWriteException if it fails to write the target image
 */
public void removeIPTC(final File src, final OutputStream os, final boolean removeSegment) throws ImageReadException, IOException, ImageWriteException {
    final ByteSource byteSource = new ByteSourceFile(src);
    removeIPTC(byteSource, os, removeSegment);
}
Also used : ByteSource(org.apache.commons.imaging.common.bytesource.ByteSource) ByteSourceFile(org.apache.commons.imaging.common.bytesource.ByteSourceFile)

Example 5 with ByteSourceFile

use of org.apache.commons.imaging.common.bytesource.ByteSourceFile in project commons-imaging by apache.

the class JpegIptcRewriter method writeIPTC.

/**
 * Reads a Jpeg image, replaces the IPTC data in the App13 segment but
 * leaves the other data in that segment (if present) unchanged and writes
 * the result to a stream.
 *
 * @param src
 *            Image file.
 * @param os
 *            OutputStream to write the image to.
 * @param newData
 *            structure containing IPTC data.
 * @throws ImageReadException if there are more than one Photoshop App13 segment, or if
 *         the Photoshop segment cannot be parsed
 * @throws IOException if it fails to read from the origin byte source, or to write to the
 *         target byte source
 * @throws ImageWriteException if it fails to write the target image
 */
public void writeIPTC(final File src, final OutputStream os, final PhotoshopApp13Data newData) throws ImageReadException, IOException, ImageWriteException {
    final ByteSource byteSource = new ByteSourceFile(src);
    writeIPTC(byteSource, os, newData);
}
Also used : ByteSource(org.apache.commons.imaging.common.bytesource.ByteSource) ByteSourceFile(org.apache.commons.imaging.common.bytesource.ByteSourceFile)

Aggregations

ByteSourceFile (org.apache.commons.imaging.common.bytesource.ByteSourceFile)50 File (java.io.File)35 ByteSource (org.apache.commons.imaging.common.bytesource.ByteSource)21 Test (org.junit.jupiter.api.Test)20 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)16 JpegImageParser (org.apache.commons.imaging.formats.jpeg.JpegImageParser)11 MethodSource (org.junit.jupiter.params.provider.MethodSource)10 BufferedImage (java.awt.image.BufferedImage)9 JpegImagingParameters (org.apache.commons.imaging.formats.jpeg.JpegImagingParameters)8 ArrayList (java.util.ArrayList)7 ImageReadException (org.apache.commons.imaging.ImageReadException)7 JpegPhotoshopMetadata (org.apache.commons.imaging.formats.jpeg.JpegPhotoshopMetadata)6 TiffContents (org.apache.commons.imaging.formats.tiff.TiffContents)5 TiffDirectory (org.apache.commons.imaging.formats.tiff.TiffDirectory)5 TiffImagingParameters (org.apache.commons.imaging.formats.tiff.TiffImagingParameters)5 TiffReader (org.apache.commons.imaging.formats.tiff.TiffReader)5 IOException (java.io.IOException)4 JpegImageMetadata (org.apache.commons.imaging.formats.jpeg.JpegImageMetadata)4 JpegUtils (org.apache.commons.imaging.formats.jpeg.JpegUtils)4 TiffField (org.apache.commons.imaging.formats.tiff.TiffField)4