Raja
Raja

Reputation: 1327

How do I resize photo during upload?

I would like to reduce size of photo before uploading to picasa using picasa java api. How can I resize photo during upload with Picasa API?

Upvotes: 1

Views: 517

Answers (2)

Ed Randall
Ed Randall

Reputation: 7560

I used a combination of ImageIO and imgscalr:

import javax.imageio.ImageIO;
import org.imgscalr.Scalr;
   
InputStream myPhotoInputStream = // new FileInputStream(file)
                                 // or FileItemStream.openStream(); from an HTTP upload
OutputStream outstream = ...
BufferedImage image = ImageIO.read( myPhotoInputStream );
int maxDimension = 1024;
image = Scalr.resize(image, maxDimension);
ImageIO.write(image, "JPEG", outstream);

Unfortunately when you resize, you lose the EXIF metadata. I have yet to find a library capable of simply saving this on read and restoring it on write. Apache commons-imaging looked promising but seems unable to write a JPEG.

Upvotes: 0

Vladimir Dyuzhev
Vladimir Dyuzhev

Reputation: 18336

As far as I see in the API, photos has to be resized before the upload. Luckily, it is easy to do in Java.

Upvotes: 0

Related Questions