location ~* 
^(.+)\.(jpg|jpeg|png|webp)/crop-w(\d+)xh(\d+)$
{
    # Matches like:
    # /19NtUg2HjeQ.jpg/crop-w100xh200
    # /img/19NtUg2HjeQ.jpg/crop-w300xh300

    rewrite 
    ^(.+)\.(jpg|jpeg|png|webp)/crop-w(\d+)xh(\d+)$ 
    $1.$2 break;
    
    image_filter crop $3 $4;

    error_page   404 = /empty;
}


location ~* 
^(.+)\.(jpg|jpeg|png|webp)/crop-h(\d+)xw(\d+)$
{
    # Matches like:
    # /19NtUg2HjeQ.jpg/crop-h100xw200
    # /img/19NtUg2HjeQ.jpg/crop-h300xw300

    rewrite 
    ^(.+)\.(jpg|jpeg|png|webp)/crop-h(\d+)xw(\d+)$ 
    $1.$2 break;
    
    image_filter crop $4 $3;

    error_page   404 = /empty;
}

location ~* 
^(.+)\.(jpg|jpeg|png|webp)/crop-w(\d+)$
{
    # Matches like:
    # /19NtUg2HjeQ.jpg/crop-w100
    # /img/19NtUg2HjeQ.jpg/crop-w300

    rewrite 
    ^(.+)\.(jpg|jpeg|png|webp)/crop-w(\d+)$ 
    $1.$2 break;
    
    image_filter crop $3 -;

    error_page   404 = /empty;
}



location ~* 
^(.+)\.(jpg|jpeg|png|webp)/crop-h(\d+)$
{
    # Matches like:
    # /19NtUg2HjeQ.jpg/crop-h100
    # /img/19NtUg2HjeQ.jpg/crop-h300

    rewrite 
    ^(.+)\.(jpg|jpeg|png|webp)/crop-h(\d+)$ 
    $1.$2 break;
    
    image_filter crop - $3;

    error_page   404 = /empty;
}


location ~* ^(.+)\.(jpg|jpeg|png|webp)/square-(\d+)$
{
    # Matches like:
    # /19NtUg2HjeQ.jpg/square-100
    # /img/19NtUg2HjeQ.jpg/square-300

    rewrite ^(.+)\.(jpg|jpeg|png|webp)/square-(\d+)$ $1.$2 break;
    
    image_filter crop $3 $3;

    error_page   404 = /empty;
}