DEV Community

Carl Riedel
Carl Riedel

Posted on

I open-sourced a tiny PHP library that turns a photo into a Pinterest pin

Making Pinterest pins by hand does not scale. If you publish content and want a pin for every post, you want it in code.

So I pulled the pin renderer out of my project and open-sourced it. It is pure PHP and GD, no dependencies, MIT licensed.

php
use SyndiKit\Pin\PinImage;

$pin = (new PinImage())
    ->font(__DIR__ . '/fonts/bold.ttf')
    ->accent(21, 88, 214);

$pin->save('photo.jpg', 'How to Grow Tomatoes in Pots', 'pin.webp', 'mysite.com');
Enter fullscreen mode Exit fullscreen mode

Give it a photo and a title, and it renders a clean 1000x1500 pin, plus a 1.91:1 version for Open Graph and Twitter cards. The photo fills the top, an accent bar divides the frame, and the title auto-fits onto a readable panel.

Install it with composer require carlstarus/syndikit-pin, or just drop in the single class file.

Repo: [(https://github.com/carlstarus/syndikit-pin)]

It came out of building SyndiKit, which automatically builds and syndicates full content sites to Pinterest. Happy to answer questions about how the rendering works.

Top comments (1)

Some comments may only be visible to logged-in visitors. Sign in to view all comments.