Skip to content

More details on Image.linear_gradient #6276

Answered by radarhere
sacrophyte asked this question in Q&A
Discussion options

You must be logged in to vote

For information about mode, see https://pillow.readthedocs.io/en/latest/handbook/concepts.html#modes

linear_gradient is not a very flexible function. When the docs say "Generate 256x256 linear gradient from black to white, top to bottom.", that's not just the default functionality, that's the entire functionality.

To generate a horizontal gradient from red to yellow in my previous example,

  • I generated the 256x256 gradient
  • Cropped it to be 50 pixels wide
  • Rotated it by 90 degrees, so that the gradient was horizontal instead of vertical
  • Used merge() to have a solid red channel, treat the gradient as the green channel, and an empty blue channel. That meant that the gradient went from full re…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@sacrophyte
Comment options

Answer selected by sacrophyte
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants