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 8907709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:59:08+00:00 2026-06-15T02:59:08+00:00

I’m trying to learn python (using python3.2), and right now I’m creating a program

  • 0

I’m trying to learn python (using python3.2), and right now I’m creating a program designed to scale images:

from PIL import Image

def newSizeChoice():
    scale = input('Please enter the scale to be applied to the image: x')
    while float(scale) <= 0:
        scale = input('Invalid: scale must be positive. Please enter a new scale: x')
    return float(scale)

def bestFilter(x):
    if x < 1:
        filter = 'ANTIALIAS'
    elif x == 2:
        filter = 'BILINEAR'
    elif x == 4:
        filter = 'BICUBIC'
    else:
        filter = 'NEAREST'
    return filter

def resize(img, width, height, scale, filter):
    width = width * scale
    height = height * scale
    newimg = img.resize((width, height), Image.filter)
    newimg.save('images\\LargeCy.png')
    newimg.show()

img = Image.open('images\\cy.png')
pix = img.load()
width, height = img.size

scale = float(newSizeChoice())
filter = bestFilter(scale)
resize(img, width, height, scale, filter)

It’s a little bit of a mess right now, because I’m still working on it, but my problem is that when I set the filter in function ‘bestFilter’, I’m not able to use it to set the filter in function ‘resize’. The error I keep getting:

Traceback (most recent call last):
  File "C:\Users\14davidson_a\Desktop\Projects\Exercises\ImageScaling.py", line 33, in <module>
    resize(img, width, height, scale, filter)
  File "C:\Users\14davidson_a\Desktop\Projects\Exercises\ImageScaling.py", line 23, in resize
    newimg = img.resize((width, height), Image.filter)
AttributeError: 'module' object has no attribute 'filter'

Question: Is there a way I can use a string to set the attribute for a module?

  • 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-06-15T02:59:09+00:00Added an answer on June 15, 2026 at 2:59 am

    You are trying to use Image.filter, which is not defined on the Image module. Perhaps you meant to use the filter argument of the method instead?

    def resize(img, width, height, scale, filter):
        width = width * scale
        height = height * scale
        newimg = img.resize((width, height), filter)
        newimg.save('images\\LargeCy.png')
        newimg.show()
    

    You don’t use the filter argument for anything else in that method.

    You’ll need to update your bestFilter() function to return a valid Image filter:

    def bestFilter(x):
        if x < 1:
            filter = Image.ANTIALIAS
        elif x == 2:
            filter = Image.BILINEAR
        elif x == 4:
            filter = Image.BICUBIC
        else:
            filter = Image.NEAREST
        return filter
    

    You could simplify that function by using a mapping:

    _scale_to_filter = {
        1: Image.ANTIALIAS,
        2: Image.BILINEAR,
        4: Image.BICUBIC,
    }
    def bestFilter(x):
        return _scale_to_filter.get(x, Image.NEAREST)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is what i have right now Drawing an RSS feed into the php,
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text

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.