Create clickable images for social media
Project description
create social media cards for LinkedIn, Facebook, and (untested) Twitter
This will create cards (images as clickable links) for social media sites. See this article for a full explanation.
Host the output of write_social_media_card
somewhere, link to it on a social-media site, and that site will build a card (or preview) with the (altered) image at local_image_path
. Clicking that preview will forward visitors to the provided url
.
:param author: The author of the page.
:param title: The title of the page.
:param description: The description of the page. Try to make this around 200
characters to avoid warnings.
:param url: The url to which the card will link.
:param remote_image_dir: The directory on the remote server where the images will
be hosted online. E.g., https://example.com/images/
:param local_image_path: The path to the image on the local machine.
:param output_image_dir: output images will be written here
:param output_html_dir: (optional) output html will be written here. If not
given, output_image_dir will be used. The flexibility is here for those who
like to keep binaries (output images) and text files (output html) separate.
:param banner_path: The path to an optional banner image. This will be added on
top of the input image.
:param banner_padding: The padding to apply to the banner image. This is the
number of pixels to add to the top of the image before pasting the banner. If
not provided, the banner height will be used. Use something other that the
banner height if you have transparency in your banner and would like to see
some of the image through it.
:param padding: Optional minimum padding around the image. This padding is added
*after* any banner is applied. I often use screenshots of my website. In
order to crop exactly around the images (this looks best with the banner), I
have to crop exactly at the text margin, which can look a bit crowded.
:effects:
- writes two images to OUTPUT_IMAGES: one for LinkedIn and one for Twitter
- writes a file to OUTPUT_HTML: the HTML file for the card
A lot of what this does is prepare your images.
- If you provide a banner image, that banner will be laid over the input image to brand your card.
- Pads LinkedIn and Facebook images to avoid cropping. LinkedIn will crop any images with an aspect ratio < 1:1.
- Pads Twitter images to 2:1. I don't have a Twitter account to check that this is necessary, but other card generators I've found pad Twitter images to 2:1, so I assume there is a reason.
See an example call in example_create_card.py
.
The LinkedIn and Twitter appropriate aspect ranges are so different that you probably want to run this script twice with different images and banners. Maybe a third time to tune for Facebook. That would be the best way to tune, because I haven't heavily parameterized or made provisions for site-specific images.
To see exactly how this works, run python -m social_media_cards.create_card
then examine the output in binaries/output_images
and output_html/
.
Test image by Frank Winkler from Pixabay
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for social_media_card-2.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0f630b56cfc0567a1eba4c81e254313ae895414e26137eb928991117610ce0ae |
|
MD5 | b0210d6983071361c9d43a4ef3ee97c1 |
|
BLAKE2b-256 | b925fb94dcb99d5a3fd58c95bdbe1e9822edbe22c8b15cdeb480acae46196636 |