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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T22:58:10+00:00 2026-06-02T22:58:10+00:00

This actually works: def tileshift(original, size, iterations): im = Image.open(original) format = im.format x,

  • 0

This actually works:

def tileshift(original, size, iterations):
    im = Image.open(original)
    format = im.format

    x, y = [float(v) for v in im.size]
    xr, yr = [float(v) for v in size]
    r = max(xr / x, yr / y)
    im = im.resize((int(round(x * r)), int(round(y * r))),
               resample=Image.ANTIALIAS)

    corners = _corners(im.size)
    lu = im.crop(corners[0])
    ru = im.crop(corners[1])
    ll = im.crop(corners[2])
    rl = im.crop(corners[3])

    # debugging each tile
    lu.save('tileshifted/lu.jpg')
    ru.save('tileshifted/ru.jpg')
    ll.save('tileshifted/ll.jpg')
    rl.save('tileshifted/rl.jpg')

    im.paste(lu, corners[1])
    im.paste(ru, corners[3])
    im.paste(ll, corners[0])
    im.paste(rl, corners[2])
    return (im, format)

def _corners(size):
    w, h = size
    return (
      (0, 0, w / 2, h / 2),
      (w / 2, 0, w, h / 2),
      (0, h / 2, w / 2, h),
      (w / 2, h / 2, w, h)
     )

Now, this actually works. I save the outputted picture and look at it. What the produced picture is is a picture with each quadrant is moved one tile clockwise.

To make my question clearer, I’ve uploaded all the pictures here:
http://www.peterbe.com/stackoverflowquestion/index.html

But! when I stopped the debugging of each corner. Ie. I comment out all the intermediate saves so it’s not like this:

    ...
    # debugging each tile
    #lu.save('tileshifted/lu.jpg')
    #ru.save('tileshifted/ru.jpg')
    #ll.save('tileshifted/ll.jpg')
    #rl.save('tileshifted/rl.jpg')
    ...

Now it stops working! And you get a composite picture where it appears that the upper left-hand corner tile has been repeated three times.

Obviously I don’t need the debugging but obviously those calls to instance.save() does something important.

UPDATE

Seems I might have found a solution. If run lu.load() right after the lu instance has been created, then it works!
Got inspiration from this one: https://stackoverflow.com/a/3838495/205832

  • 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-02T22:58:11+00:00Added an answer on June 2, 2026 at 10:58 pm

    Per the documentation for crop: “This is a lazy operation. Changes to the source image may or may not be reflected in the cropped image. To get a separate copy, call the load method on the cropped copy.”

    So each of the corner crops, without the save, is a reference to a portion of the original image, rather than a copy, so you paste LU to RU, then try to paste from RU to RL but get LU again, and so on. The save apparently forces PIL to make a copy out of the crops.

    (Also, you didn’t actually ask a question. Your question was implicit, but if you actually go all the way to formulating a clear and concise question, then as often as not, you’ll realize the answer, or realize you need to provide more information which may lead you to the answer.)

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

Sidebar

Related Questions

If I use INT(12) vs INT(10) or INT(8) what will this actually do in
My helper code looks like this (and works fine btw): module ProvidersHelper def call_to_review(provider)
I'm curious how this code actually works. In particular what does request.__class__.user = LazyUser()
Problem This question actually came up at work today. We are planning an experiment
actually i use this method to show similar words for a search request.. $query
Simple question - what does this actually do? var oq = (ObjectQuery<TEntity>)L2EQuery; return ExecuteFirstorDefault<TEntity>(oq,
I have seen code like this (actually seeing another person type it up): catch
Could someone explain in layman terms what this actually does? XmlTextReader textReader = new
I understand that 2 options are available: Non-persistent Persistent But what does this actually
referring to yesterday's post, this woke me up this morning. Why does this actually

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.