Bug 57361

Summary: [PATCH] Cropping background images.
Product: POI Reporter: artyom.nikiforov
Component: XSLFAssignee: POI Developers List <dev>
Severity: normal Keywords: PatchAvailable
Priority: P2    
Version: 3.10-FINAL   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Attachments: patch + samples of cropping the background images.

Description artyom.nikiforov 2014-12-17 07:59:35 UTC
Created attachment 32299 [details]
patch + samples of cropping the background images.

Hi, folks!
I'm trying to convert pptx slides to images with the code:
        FileInputStream is = new FileInputStream("slideshow.pptx");
        XMLSlideShow ppt = new XMLSlideShow(is);
        Dimension pgsize = ppt.getPageSize();

        Slide[] slide = ppt.getSlides();
        for (int i = 0; i &lt; slide.length; i++) {

            BufferedImage img = new BufferedImage(pgsize.width, pgsize.height, BufferedImage.TYPE_INT_RGB);
            Graphics2D graphics = img.createGraphics();
            //clear the drawing area
            graphics.fill(new Rectangle2D.Float(0, 0, pgsize.width, pgsize.height));


            //save the output
            FileOutputStream out = new FileOutputStream("slide-"  + (i+1) + ".png");
            javax.imageio.ImageIO.write(img, "png", out);

If background image is bigger than a slide, then it's cropped to a slide width and height. So you get left top corner of an image as a result. If background image is smaller, then it takes only a part of slide's area(see the attached files).

BTW, I've made the changes in attached patch to eliminate the issue.

In the patch we just transform image to slide's size. Obviously the solution is wrong, because we should preserve whole image unscaled till the last render(otherwise we'll loose quality), but it solved the problem of cropping the background image for me.

Comment 1 Nick Burch 2014-12-21 06:24:27 UTC
Any chance you could work up a small unit test for this?
Comment 2 Andreas Beeker 2016-03-23 22:57:32 UTC
I don't understand the proposed general scaling to page size.
Please add at least a .ppt/x which shows your issue - i'll then adapt your code.
My goal for rendering is always to stay close to the rendering of powerpoint.

As this issue hasn't got any attention for over a year I'm closing this as 
wontfix - feel free to reopen it (... with a .ppt/x attached)

Btw. I've tried to download Sanders slides, but only found the mentioned slides 
of 2008 on slideshare [1] and I'm not registering with linkedIn
just for downloading those.

[1] http://de.slideshare.net/sctemme/apache-performance-tuning-scaling-up
Comment 3 Nick Burch 2016-03-23 23:04:53 UTC
You just need to search the Apache SVN server harder Andreas! ;-)

Sander's slides can be downloaded from svn at https://svn.apache.org/repos/infra/apachecon/archive.apachecon.com/eu2008/program/materials/2411-Performance_Up.pptx / published at http://archive.apachecon.com/eu2008/program/materials/2411-Performance_Up.pptx
Comment 4 Andreas Beeker 2016-03-24 00:11:17 UTC
... although the background images fits nicely, it will give a NPE on page 5, because the BLIP fill is a AlternateContent.
I'll (try to) fix it ..