JPEG/JPG has less size after it’s stamped

Hello,

I hit the situation that my JPEG/JPG file’s size becomes less when I put a stamp (text or image) on it using aspose-imaging.
Is it possible to do something to avoid size decreasing while stamping JPEG/JPG?

Additional information: I had same question about multipage TIFF file previously: Multipage TIFF has less size after it's stamped
But I’m not sure how I should use JpegOptions in this case, maybe do you have any examples.
Thank you in advance.

@paultomsky

Please provide the source file, generated file and used sample code along with desired output. We will investigate that on our end to help you further.

hi @mudassir.fayyaz,
in zip you may find source file and result image with text stamp.
JPEG_examples.zip (24.6 KB)
Also, here’s a sample of code I use to stamp:

 class Test {
        public ByteBucketOutputStream stampImage(InputStream is) throws IOException {
            try (ByteBucketOutputStream bucketOutputStream = new ByteBucketOutputStream();
                 Image image = Image.load(is)) {
                RectangleF rectangle = new RectangleF();
                rectangle.setTop(10);
                Font font = new Font("Courier New", 14,0, GraphicsUnit.Pixel);
                SolidBrush brush = new SolidBrush();
                brush.setColor(Color.getBlack());
                new Graphics(image).drawString("text text",font,brush, rectangle);
                image.save(bucketOutputStream);
                return bucketOutputStream;
            } finally {
                // prevent memory leaks
                if (is != null) {
                    is.close();
                }
            }
        }
    }

@paultomsky

I have created a ticket with ID IMAGINGNET-4433 in our issue tracking system to further investigate and resolve the issue. This thread has been linked with the issue so that you may be notified once the issue will be fixed.

@paultomsky

The reduction in size occurs because by default, jpeg is stored with a quality of 75; and this means compression and, as a result, a reduction in the file size.

Please, share followed code with the customer.

Image image = Image.load("jpeg_test_file_SOURCE.jpeg");
try
{
    RectangleF rectangle = new RectangleF();
    rectangle.setTop(10);
    Font font = new Font("Courier New", 14,0, GraphicsUnit.Pixel);
    SolidBrush brush = new SolidBrush();
    brush.setColor(Color.getBlack());
    new Graphics(image).drawString("text text",font,brush, rectangle);
    // This code is important
    JpegOptions options = new JpegOptions();
    options.setQuality(95); // by default quality == 75
    image.save("jpeg_test_file_out.jpeg", options);
}
finally
{
    // prevent memory leaks
    image.close();
}

@paultomsky

Can we close the issue on our end or if there is any further feedback from your side that we need to consider on our end.

@mudassir.fayyaz , yes, sure, you can close the issue. Thank you for your help!