Skip to content

itsnotlupus/reddit_thumbnails

Repository files navigation

reddit_thumbnails

Code by itsnotlupus. Initial concept by cfabbro.

# BIG IDEA

Reddit can show thumbnails for submissions, but not for comments.
Some sub-reddits have in the past used some creative CSS hacks to enable image posting within a comment, but that was disabled due to some IP# leakage it caused.

Now, reddit lets moderators upload up to 50 images per sub-reddit, and those images can be used in custom CSS rules for that sub-reddit.

So the idea is: Let's use some of those images to store and display thumbnails for comments.
Since 50 is a small number, we're storing all the comment thumbnails for a given submission in the same image, and use CSS slicing to show the right piece in the right place.
Roughly, we should be able to fit about 100 thumbnails per story with that approach.
By default, this script will use half of the 50 images for thumbnails, leaving moderators with room to customize their themes with images.

# HOW IT WORKS

The script will need to run at regular interval on a box somewhere. A cron job would work nice for that.
Every time it runs, the script will scan the top 25 stories on your sub-reddit, and build a list of comments that link to an image.
It will then download each image, create thumbnails for them, aggregate them into one image per story, and feed it all to Reddit, along with some CSS rules to go with it.
Downloaded images and thumbnails are cached locally, so they won't be fetched more than once.

# GETTING STARTED

You'll need a php command line interpreter with curl and gd extensions installed.
Put all the repository files in a directory.
Get your reddit cookies, and store them in a file called "cookies" in the same directory.
Next, open Main.php in a text editor, and look at the define() statements:
 - change the SUB value to point to your subreddit's name instead of "cfabbro".
 - change the BGCOLOR value to match the background color of your subreddit theme.
If you already have custom CSS defined for your sub-reddit, copy it in the file "custom.css".
The content of custom.css will overwrite any existing CSS rules once you run the script.

# NOTES

Other file will be created in the directory.
Notably, sub-directories named "images" and "thumbnails" will contain cached copies of every image downloaded and thumbnail generated by the script.
A file called "reddit.params" will contain some values the script will re-fetch from Reddit every 30 minutes.
The file "updater.state" keeps track of what has been sent to the server, to know when to avoid redundant requests to Reddit, and to know when to delete images that arent' in use anymore.

That's it.

About

Adds thumbnails to comments within a given sub-reddit.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages