Edit: fixed it my self with a little confidence lol

changed this
Code: 
$cache_file = md5($cachename) . '.png';
to this
Code: 
$cache_file = md5($cachename) . '.jpg';