Use Pil to synthesize images to prepare for the next step

Source: Internet
Author: User
I watched everyone diligently practice what they liked. Then I looked at my exercises and looked at them with shame.

Let's get down to the point. These two days, they watched Tianya participate in the T-shirt competition. It was very interesting. Although they did not make a picture, they also planned to make some contributions to the curve and build a T-shirt Synthesis System.

The first step is to combine the two images into one, since the post is written, it is obvious that we want to use python to do, download Pil (http://www.pythonware.com/products/pil/) first)

Select two clips:

Images related to this topic

Images related to this topic

OK. The next task is to paste the thumbnail to the big image. Take a look at the Pil documentation. The procedure is as follows:

1. read two images
2. Set the two images to the rgba or l mode. For details, see the document.
3. Create a whiteboard with the same size as a large image.
4. Add paste to the whiteboard.
5. Combine the whiteboard and big image

Python follows this step, and the entire code is very concise:

Logo = image. Open ("logo.gif") # read two images
Dog = image. Open ("dog.jpg") # read two images
Layer = image. New ('rgba', logo. Size, (,) # create a whiteboard image of the same size as a large image.
Layer. paste (DOG) # upload the small image paste to the whiteboard.
Img1 = image. Composite (layer, logo, layer) # combine the whiteboard and big image
Img1.show () # view the merged image

The synthesis result is as follows:
Images related to this topic

OK. With this foundation, we can do more things :)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.