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

  • SEARCH
  • Home
  • 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 7537983
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T06:59:37+00:00 2026-05-30T06:59:37+00:00

Any ideas how to use Python with the PIL module to shrink select all?

  • 0

Any ideas how to use Python with the PIL module to shrink select all? I know this can be achieved with Gimp. I’m trying to package my app as small as possible, a GIMP install is not an option for the EU.

Say you have 2 images, one is 400×500, other is 200×100. They both are white with a 100×100 textblock somewhere within each image’s boundaries. What I’m trying to do is automatically strip the whitespace around that text, load that 100×100 image textblock into a variable for further text extraction.

It’s obviously not this simple, so just running the text extraction on the whole image won’t work! I just wanted to query about the basic process. There is not much available on Google about this topic. If solved, perhaps it could help someone else as well…

Thanks for reading!

  • 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-30T06:59:39+00:00Added an answer on May 30, 2026 at 6:59 am

    If you put the image into a numpy array, it’s simple to find the edges which you can use PIL to crop. Here I’m assuming that the whitespace is the color (255,255,255), you can adjust to your needs:

    from PIL import Image
    import numpy as np
    
    im = Image.open("test.png")
    pix = np.asarray(im)
    
    pix = pix[:,:,0:3] # Drop the alpha channel
    idx = np.where(pix-255)[0:2] # Drop the color when finding edges
    box = map(min,idx)[::-1] + map(max,idx)[::-1]
    
    region = im.crop(box)
    region_pix = np.asarray(region)
    

    To show what the results look like, I’ve left the axis labels on so you can see the size of the box region:

    from pylab import *
    
    subplot(121)
    imshow(pix)
    subplot(122)
    imshow(region_pix)
    show()
    

    enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use the EasyDialogs python module to produce some simple dialog boxes
I am really new to python and I can't find any information about this.
I don't have any idea how to use this class in .net. Anyone wants
Any ideas why this won't validate here: http://validator.w3.org/#validate_by_input It seems the form input tags
I am trying to automate a downloading process. In this I want to know,
I'm trying to use Selenium (in Python) to extract some information from a website.
I'm currently using os.popen() but have been recommended to use subprocess.popen() instead. Any ideas
I am using eclipse and cygwin gcc compiler. Trying to use the Python.h for
I'm trying to use polymorphic_on on a python class with several inheritances: engine =
I am trying out MongoEngine , a DRM library for Python to use with

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.