Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Number of seconds to read an image, per Medium's algorithm: https://blog.medium.com/read-time-and-you-bc2048ab620c
<?php
function image_reading_seconds( $count ) {
// Every image start with 3 seconds
$reading_seconds = $count * 3;
// The first 9 images also add the cumulative
// amount of seconds calculated by 10 seconds
// minus the image count for each image.
$reading_seconds += 9 >= $count
? 10 * $count - intval( ( $count**2 + $count ) / 2.0 )
: 45; // 9 + 8 + 7 ... 3 + 2 + 1
return $reading_seconds;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.