Amazon_S3_And_CloudFront::remove_size_from_filename PHP Method

remove_size_from_filename() public method

Remove size from filename (image[-100x100].jpeg).
public remove_size_from_filename ( string $url, boolean $remove_extension = false ) : string
$url string
$remove_extension boolean
return string
    public function remove_size_from_filename($url, $remove_extension = false)
    {
        $url = preg_replace('/^(\\S+)-[0-9]{1,4}x[0-9]{1,4}(\\.[a-zA-Z0-9\\.]{2,})?/', '$1$2', $url);
        if ($remove_extension) {
            $parts = pathinfo($url);
            $url = str_replace('.' . $parts['extension'], '', $url);
        }
        return $url;
    }

Usage Example

 /**
  * URL cache failure.
  *
  * @param string $url
  * @param array  $to_cache
  */
 protected function url_cache_failure($url, &$to_cache)
 {
     $full = $this->as3cf->remove_size_from_filename($url);
     $failure = array('timestamp' => time());
     $to_cache[$full] = $failure;
     if ($full !== $url) {
         $to_cache[$url] = $failure;
     }
 }
Amazon_S3_And_CloudFront