Skip to content

Instantly share code, notes, and snippets.

@mikeschinkel
Last active November 9, 2018 09:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikeschinkel/6cd04424d202d96384d9fdd8ea5a3076 to your computer and use it in GitHub Desktop.
Save mikeschinkel/6cd04424d202d96384d9fdd8ea5a3076 to your computer and use it in GitHub Desktop.
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