cacheImageFields issue
-
Hi Chester, hope you’re keeping well! I’m trying to use cacheImageFields but it’s only giving me the small and large thumbnails from airtable. I’m using this for my query:
$sizes = array(“medium”,”homepage-thumb”);
$query->cacheImageFields(“Featured Image”,$sizes);Am I doing something wrong?
-
This topic was modified 7 years, 11 months ago by
mcloone.
-
This topic was modified 7 years, 11 months ago by
-
Ok here’s the output:
AIRPRESS LOADED Projects VirtualPost ^project/(.*)/? 200 1 0.4 Projects?filterByFormula={Slug} = '22-jump-street' 200 133 1.92 Portfolio?filterByFormula=OR(...one of 133 ids...) wp_get_image_editor error: /Users/TinymillTim/dev/wordpress/wp-content/airpress-image-cache/attcuZdmCtCfdE31F-full-image.jpg ######################################### WP_Error Object ( [errors] => Array ( [invalid_image] => Array ( [0] => JPEG datastream contains no image
/Users/TinymillTim/dev/wordpress/wp-content/airpress-image-cache/attcuZdmCtCfdE31F-full-image.jpg’ @ error/jpeg.c/JPEGErrorHandler/322
))
[error_data] => Array
(
[invalid_image] => /Users/TinymillTim/dev/wordpress/wp-content/airpress-image-cache/attcuZdmCtCfdE31F-full-image.jpg
))
#########################################
wp_get_image_editor error: /Users/TinymillTim/dev/wordpress/wp-content/airpress-image-cache/att19145ONOr6ZnGo-large.png
#########################################
WP_Error Object
(
[errors] => Array
(
[invalid_image] => Array
(
[0] => Read Exception `/Users/TinymillTim/dev/wordpress/wp-content/airpress-image-cache/att19145ONOr6ZnGo-large.png’ @ error/png.c/MagickPNGErrorHandler/1630
))
[error_data] => Array
(
[invalid_image] => /Users/TinymillTim/dev/wordpress/wp-content/airpress-image-cache/att19145ONOr6ZnGo-large.png
))
#########################################
`
Can you look in your airpress-image-cache folder and see if there’s any corrupted images? Zero bytes or simply not viewable when you double click? I’m going to add some better debugging to see if we can’t narrow it down. I’ll let you know.
I’ve pushed up 1.1.28 which contains a different method of actually doing the download (which may resolve this issue) as well as slightly better debugging output.
also, subfolders are now used in airpress-image-cache, which you’re probably the only person in the world this will affect in that it’ll refetch the images. But that’s why it’s in a cache folder and not a storage folder ??
Let me know if you keep seeing image errors.
OK, I updated, removed everything from the cache and started again, same error. I did find a corrupt image in the cache after. This is the error from the logs, the image in log here is the corrupted one.
I loaded everything without the image caching and all images loaded fine so I don’t think it’s a problem with the image. Also, I just check on a different project page with a lot of images and ran into the same error ??AIRPRESS LOADED Projects VirtualPost ^project/(.*)/? 200 1 0.35 Projects?filterByFormula={Slug} = '22-jump-street' 200 132 1.4 Portfolio?filterByFormula=OR(...one of 132 ids...) wp_get_image_editor error: file exists /Users/TinymillTim/dev/wordpress/wp-content/airpress-image-cache/Portfolio/att8D57459VdxCJYz-full-image.jpg ######################################### WP_Error Object ( [errors] => Array ( [invalid_image] => Array ( [0] => Premature end of JPEG file
/Users/TinymillTim/dev/wordpress/wp-content/airpress-image-cache/Portfolio/att8D57459VdxCJYz-full-image.jpg’ @ error/jpeg.c/JPEGErrorHandler/322
))
[error_data] => Array
(
[invalid_image] => /Users/TinymillTim/dev/wordpress/wp-content/airpress-image-cache/Portfolio/att8D57459VdxCJYz-full-image.jpg
))
#########################################
Cached remote image in 0.0147 seconds to /Users/TinymillTim/dev/wordpress/wp-content/airpress-image-cache/Portfolio/attpsuyMZCsbYcUsw.jpg
Cached remote image in 0.0107 seconds to /Users/TinymillTim/dev/wordpress/wp-content/airpress-image-cache/Portfolio/attrpnqNKT91D8AyX.jpg
Cached remote image in 0.0131 seconds to /Users/TinymillTim/dev/wordpress/wp-content/airpress-image-cache/Portfolio/attyTJ1JDJAoRSFim.jpg
Cached remote image in 0.0121 seconds to /Users/TinymillTim/dev/wordpress/wp-content/airpress-image-cache/Portfolio/attbID83pGlpTHz9k.jpg
Cached remote image in 0.0319 seconds to /Users/TinymillTim/dev/wordpress/wp-content/airpress-image-cache/Portfolio/attWDjrtPv2H8inSi.jpg
Cached remote image in 0.0162 seconds to /Users/TinymillTim/dev/wordpress/wp-content/airpress-image-cache/Portfolio/attn84URRgAM8x4di.jpg`I’m guessing that the script runs until it times out, at which point any image “in transit” gets corrupted.
I’m going to try using
ini_get('max_execution_time')
to determine the max execution limit, or just limit it to 20 seconds. Any images not downloaded in that time will simply be given the URL of the “large” image from Airtable along with a flag that it still needs to be processed. Then on subsequent loads it has a chance to complete.Also on the roadmap will be a “utility” on the WP Admin interface where you can type in a table name and it will use AJAX to pre-cache all the images. That should cover most scenarios where people want to use Airpress but have an extremely large library of images.
Thanks for your feedback and your patience.
The pre-caching sounds awesome. I think for now I’ll go back to what I did before and use wordpress’s wp_insert_attachment to put the images directly into wordpress. Doing it this way is useful for us as sometimes we want to change the crop of an image without changing the photo that’s on airtable.
If you’re willing, I would love to see your code sample so I can see why that works and the other options don’t.
weird, I did add it just now but think I accidentally deleted it when editing. I just noticed that for some reason it’s doubling up the images so I need to fix that. I initially did this when I only needed to load in one image per page so it’s probably tripping over itself. But basically it goes through each image at a time, looks if it’s in wordpress, if not then uploads, refreshes and (hopefully) moves on to the next.
This is my upload function:
function uploadRemoteImage($image, $name, $id = null){ $get = wp_remote_get( $image ); $type = wp_remote_retrieve_header( $get, 'content-type' ); error_log($image. ' ' . $name); if (!$type){ return false; } $mirror = wp_upload_bits( basename( $image ), '', wp_remote_retrieve_body( $get ) ); if ($id){ $attachment = array( 'post_title'=> $name, 'post_mime_type' => $type, 'ID' => $id, ); } else { $attachment = array( 'post_title'=> $name, 'post_mime_type' => $type, ); } $attach_id = wp_insert_attachment( $attachment, $mirror['file'] ); require_once(ABSPATH . 'wp-admin/includes/image.php'); $attach_data = wp_generate_attachment_metadata( $attach_id, $mirror['file'] ); wp_update_attachment_metadata( $attach_id, $attach_data ); $url= strtok($_SERVER["REQUEST_URI"],'?'); redirect($url); }
So I started to get a similar execution error using my script on the pages with tons of images. I fixed it by changing max_execution_time to 180. I tried cacheimagefields after doing this but it still timed out. I’m still getting doubling up of images but haven’t spent time looking at that yet.
v1.1.31 has been released. It limits image caching to 25 seconds at a time. It’s really conservative, but in the long run it’s the safest approach since many hosts will have different max_execution times and methods of implementing. In a future release I’ll make the 25 second limit a filtered variable so that it can be modified. Try this out and see if simply reloading the page successfully works for your huge amount of images. I test with 25 3+ MB images and it took 4 page loads, but it worked with no corrupt images or errors. Here’s hoping!
- The topic ‘cacheImageFields issue’ is closed to new replies.