Topic on Talk:Requests for comment/Standardized thumbnails sizes

Generate statistics for most requested non-existing thumb widths

1
Subfader (talkcontribs)

To add more useful thumb widths to $wgUploadThumbnailRenderMap I generate a list of all thumb widths that are created because the thumb didn't exist yet.

Maybe it's useful to someone: MediaTransformOutput.php > hasFile()

	public function hasFile() {		
		// Generate statistics for most requested non-existing thumb widths
		// includes x1.5 and x2
		global $wgUploadThumbnailRenderMap;
		if( $this->path != null // not when thumb size is >= original and original is returned
		    && !$this->isError() // only if thumb is really created
		    && !in_array( $this->width, $wgUploadThumbnailRenderMap ) // not if is in job list to be created
		  ) {	
			$file = '/path/to/thumbs_not_existing_on_request';
			$current = file_get_contents($file);
			$current .= $this->width . "\n";
			file_put_contents($file, $current);
		}
		
		// If TRANSFORM_LATER, $this->path will be false.
		// Note: a null path means "use the source file".
		return ( !$this->isError() && ( $this->path || $this->path === null ) );
	}

After some hours / days grab the most requested thumb sizes:

sort /path/to/thumbs_not_existing_on_request | uniq -c | sort -rn | head -n 30

Example after some hours:

99 240
60 170
6 320
...  

>> Adding 240 and 170 to $wgUploadThumbnailRenderMap might be worth it.

Reply to "Generate statistics for most requested non-existing thumb widths"