I am working on a project built in Laravel 5.8 where i need to look through 3 different image Sources for an img
tag.
For example first I will put src
of "https://yw-web.yoworld.com/cdn/items/12/73/127305/127305.png"
if this does not return an image then i will provide second address like
"https://yw-web.yoworld.com/cdn/items/12/73/127305/127305_130_100.gif"
if still no image found I will try third address like
"https://yw-web.yoworld.com/cdn/items/12/73/127305/127305_60_60.gif"
and if all three of these does not work then this image will be loaded
"https://yoworld.info/assets/image_not_found.jpg"
recently I have implemented this snippet which seems to work fine but it is taking a lot of time to execute.
HTML:
<img class="my-auto mx-auto" src="{{$img}}">
PHP:
$src= 'https://yw-web.yoworld.com/cdn/items/12/73/127305/127305';
if(@getimagesize($src.'.png')){
$img=$src.'.png';
}
elseif(@getimagesize($src.'_130_100.gif')){
$img=$src.'_130_100.gif';
}
elseif(@getimagesize($src.'_60_60.gif')){
$img=$src.'_60_60.gif';
}
else{
$img=url('img/image_not_found.jpg');
}
file_exists() does not work because I am accessing these images from another domain and cURL is also taking a lot of time.
Kindly suggest me an approach which takes less time. I can also use Javascript it provides a solution.