Jump to content

Rotating Image PHP Function Problem


Shaun333

Recommended Posts

Hi All,

 

I am having an issue with my image rotating PHP function code which I have attached below.

1% of the time it can rotate through 3 of the 10 pics before stopping. 99% of the time it doesn't work at all.

The issue that is popping up in the Developer console of Firefox is "[12:25:28.802] Image corrupt or truncated: http://www.mywebsite.com/wp-content/uploads/script-thumbs/79/7979_5.jpg @ http://www.mywebsite.com/wp-content/uploads/script-thumbs/79/7979_5.jpg".

It is not specific to Firefox.

 

Any assistance would be appreciated.

function script_thumb($prefix,$title){

    $saved_thmb = get_post_meta( get_the_ID(),'saved_thmb',true);

    $subPath = tubeace_sub_dir_path(get_the_ID());

    $upload_dir = wp_upload_dir();
    $thumb_url = $upload_dir[baseurl]."/script-thumbs/".$subPath."/";

    if($saved_thmb==1){
      $thumb = $thumb_url."/".get_the_ID()."_1.jpg";
    } elseif($saved_thmb>1) {

      $def_thmb = get_post_meta( get_the_ID(),'def_thmb',true);

      $thumb = $thumb_url."/".get_the_ID()."_".$def_thmb.".jpg";

      $rotate_thumbs = "onmouseover=\"thumbStart('$prefix-".get_the_ID()."', $saved_thmb, '$thumb_url');\"
       onmouseout=\"thumbStop('$prefix-".get_the_ID()."', '$thumb_url', '$def_thmb');\"";
    } else {
      return;
    }

    $thumb = "<img class=\"img-responsive\" src=\"$thumb\" $rotate_thumbs id=\"$prefix-".get_the_ID()."\" alt=\"".esc_attr($title)."\">";
    return $thumb;
}

Cheers,

Shaun

Link to comment
https://forums.phpfreaks.com/topic/288825-rotating-image-php-function-problem/
Share on other sites

Make sure get_the_ID() is actually returning an id for each one.

Before even using the thumb location...check to see if the image actually exists with file_exists()

 

 

if (file_exists($thumb)) {
   $thumb = "<img class=\"img-responsive\" src=\"$thumb\" $rotate_thumbs id=\"$prefix-".get_the_ID()."\" alt=\"".esc_attr($title)."\">";
return $thumb;
} else {
return;
}

Thinking about your firefox error tells me that the file extension may have been changed, like gd,  imagemagick or whatever does it is doing it incorrectly.

 

But a most likely cause is that the images are just way too large, try optimizing them first.

Thinking about your firefox error tells me that the file extension may have been changed, like gd,  imagemagick or whatever does it is doing it incorrectly.

 

But a most likely cause is that the images are just way too large, try optimizing them first.

Thanks for your replies. I will look into optimizing them. Also, are you able to assist on where I should include your code snippet within the source code I provided?

 

Cheers,

Shaun :)

Thinking about your firefox error tells me that the file extension may have been changed, like gd,  imagemagick or whatever does it is doing it incorrectly.

 

But a most likely cause is that the images are just way too large, try optimizing them first.

Btw, the strange thing is that the files do exist and when I visit the URL directly the correct thumbnail is displayed. But it comes up as "Image corrupt or truncated:" when I mouseover on the index page.

It has me stumped. Could it be cycling too fast and missing the information it requires? If so, is it possible to setup my source so that it doesn't cycle to the next image until it has loaded the current one? That's all I can think of :/

seeing as how you use the same $thumb variable, this looks like a good place

 

function script_thumb($prefix,$title){
    $saved_thmb = get_post_meta( get_the_ID(),'saved_thmb',true);
    $subPath = tubeace_sub_dir_path(get_the_ID());
    $upload_dir = wp_upload_dir();
    $thumb_url = $upload_dir[baseurl]."/script-thumbs/".$subPath."/";
    if($saved_thmb==1){
      $thumb = $thumb_url."/".get_the_ID()."_1.jpg";
    } elseif($saved_thmb>1) {
      $def_thmb = get_post_meta( get_the_ID(),'def_thmb',true);
      $thumb = $thumb_url."/".get_the_ID()."_".$def_thmb.".jpg";
      $rotate_thumbs = "onmouseover=\"thumbStart('$prefix-".get_the_ID()."', $saved_thmb, '$thumb_url');\"
       onmouseout=\"thumbStop('$prefix-".get_the_ID()."', '$thumb_url', '$def_thmb');\"";
    } else {
      return;
    }
    if (file_exists($thumb)) {
   $thumb = "<img class=\"img-responsive\" src=\"$thumb\" $rotate_thumbs id=\"$prefix-".get_the_ID()."\" alt=\"".esc_attr($title)."\">";
return $thumb;
} else {
return;
}
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.