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
Share on other sites

Sorry, I am not linking my website as it is pornographic related. I just changed the URL to that. I have checked all the thumb URLs by visiting them to see if the images appear correctly - which they do.

 

Regards,

Shaun

Edited by Shaun333
Link to comment
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;
}
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

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 :/

Edited by Shaun333
Link to comment
Share on other sites

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;
}
}
Edited by QuickOldCar
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.