1

In a nut-shell, I am trying to display feeds from other sites, that sometimes have IMG elements. Ideally, these IMG should be loaded by an external proxy, such as Aratech or Weserv. In my code below, I am trying to use Weserv. Then, if this is not working, I'd like to use Aratech. If this is also not working, I want to use the original IMG SRC. Finally, if this fails with any other status code then 200, I want to display another IMG.

I believe the code, as bad as it looks, will explain it better. This is what I have:

$proximage1 = rtrim(preg_replace ('/https:\/\/|http:\/\//','https://images.weserv.nl/?w=800&output=webp&url=',$img->getAttribute('src'),1),'/');  //proxied img
$arrayproximage1 = @get_headers($proximage1);
$stringproximage1 = $arrayproximage1[0];
$proximage1200 = strpos($stringproximage1, "200");


$proximage2 = rtrim(preg_replace ('/https:\/\/|http:\/\//','https://imagex.aratech.co/?w=800&q=75&il&output=webp&url=',$img->getAttribute('src'),1),'/');  //proxied img
$arrayproximage2 = @get_headers($proximage2);
$stringproximage2 = $arrayproximage2[0];
$proximage2200 = strpos($stringproximage2, "200");
            
$arrayproximage3 = @get_headers($img->getAttribute('src'));  //original img headers
$stringproximage3 = $arrayproximage3[0];
$proximage3200 = strpos($stringproximage3, "200"); 

if (($proximage1200 !== false) && ($proximage2200 === false) && ($proximage3200 === false)) {
    $img->setAttribute( 'src', $proximage1 );
}
if (($proximage1200 === false) && ($proximage2200 !== false) && ($proximage3200 === false)) {
    $img->setAttribute( 'src', $proximage2 );
} 
if (($proximage1200 === false) && ($proximage2200 === false) && ($proximage3200 !== false)) {
     $img->setAttribute( 'src', $img->getAttribute('src') );  // this is the original IMG SRC
} 
if (($proximage1200 === false) && ($proximage2200 === false) && ($proximage3200 === false)) {
     $img->setAttribute( 'src', 'https://some-url-that-can-finally-load-an-img' );
}

What happens is that the page loads the original IMG SRC, skipping somehow the proxified images.weserv.nl and imagex.aratech.co. Any ideas, any way to fix this?

Again, my goal is to use Weserv, then if this doesn't URL doesn't display a 200 status use the Aratech service, then if this fails the original IMG SRC and finally a static IMG. All depends on the 200 status.

1
  • 1
    The example is above "What happens is that the page loads the original IMG SRC, skipping somehow the proxified images.weserv.nl and imagex.aratech.co." Commented Aug 1, 2022 at 17:08

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.