Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6566677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:14:42+00:00 2026-05-25T14:14:42+00:00

Is there a framework which is able to remove the white space (rectangular) of

  • 0

Is there a framework which is able to remove the white space (rectangular) of an image. We create Image Thumbnails from technical drawings which are unfortunately in PDF format. We convert the PDF to SVG and then to JPG. Often the technical drawings are very small and now placed in the upper left corner of the thumbnail:

+---------+----------------------+
|         |                      |
| (image) |                      |
|         |                      |
+---------+                      |
|                                |
|                                |
|                                |
|                                |
|              (empty space)     |
|                                |
|                                |
+--------------------------------+

So how can I easily remove the empty space and shrink the JPG file?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T14:14:43+00:00Added an answer on May 25, 2026 at 2:14 pm

    It can be done in JAI as is demonstrated in this thread. Or here’s some Java code I just wrote which can be used to do it:

    public class TrimWhite {
        private BufferedImage img;
    
        public TrimWhite(File input) {
            try {
                img = ImageIO.read(input);
            } catch (IOException e) {
                throw new RuntimeException( "Problem reading image", e );
            }
        }
    
        public void trim() {
            int width  = getTrimmedWidth();
            int height = getTrimmedHeight();
    
            BufferedImage newImg = new BufferedImage(width, height,
                    BufferedImage.TYPE_INT_RGB);
            Graphics g = newImg.createGraphics();
            g.drawImage( img, 0, 0, null );
            img = newImg;
        }
    
        public void write(File f) {
            try {
                ImageIO.write(img, "bmp", f);
            } catch (IOException e) {
                throw new RuntimeException( "Problem writing image", e );
            }
        }
    
        private int getTrimmedWidth() {
            int height       = this.img.getHeight();
            int width        = this.img.getWidth();
            int trimmedWidth = 0;
    
            for(int i = 0; i < height; i++) {
                for(int j = width - 1; j >= 0; j--) {
                    if(img.getRGB(j, i) != Color.WHITE.getRGB() &&
                            j > trimmedWidth) {
                        trimmedWidth = j;
                        break;
                    }
                }
            }
    
            return trimmedWidth;
        }
    
        private int getTrimmedHeight() {
            int width         = this.img.getWidth();
            int height        = this.img.getHeight();
            int trimmedHeight = 0;
    
            for(int i = 0; i < width; i++) {
                for(int j = height - 1; j >= 0; j--) {
                    if(img.getRGB(i, j) != Color.WHITE.getRGB() &&
                            j > trimmedHeight) {
                        trimmedHeight = j;
                        break;
                    }
                }
            }
    
            return trimmedHeight;
        }
    
        public static void main(String[] args) {
            TrimWhite trim = new TrimWhite(new File("...\\someInput.bmp"));
            trim.trim();
            trim.write(new File("...\\someOutput.bmp"));
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create gallery application which would get thumbnails and metadata from web
I'm trying to make a simple css framework which allows me to switch from
Are there any good JavaScript frameworks out there which primary audience is not web
Which are the most advanced frameworks and tools there are available for python for
We are using ASP.net MVC. Which of these is the best DI framework Ninject
Is there a framework that can be used to enable a C# Windows Service
Is there any framework for querying XML SQL Syntax, I seriously tire of iterating
Is there any framework/library for using ASP.NET Membership Provider with confirmation email, something ready
Is there any framework that would allow me to integrate paypal with twitter, such
Is there any upnp framework for CF .NET? There is mono.upnp source but it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.