Thread Starter
jnz31
(@jnz31)
ok. found the problem.
while image_get_intermediate_size returns all required meta-data (even with perfectly correct ‘url’ value), image_make_intermediate_size doesn’t. the second one only returns the values, that are shown in my previous post aka. file, width, height & mime-type. tried to solve this, but ran out of corrupt images, so i can’t find a way to test this properly.
could this work..?
if image_make_intermediate_size create an array $repeat and redo the function (cause now we do have all values to use image_get_intermediate_size)..?
function wp_generate_attachment_metadata_custom( $attachment_id, $file, $thumbnails = NULL ) {
$attachment = get_post( $attachment_id );
$metadata = array();
if ( preg_match('!^image/!', get_post_mime_type( $attachment )) && file_is_displayable_image($file) ) {
$imagesize = getimagesize( $file );
$metadata['width'] = $imagesize[0];
$metadata['height'] = $imagesize[1];
list($uwidth, $uheight) = wp_constrain_dimensions($metadata['width'], $metadata['height'], 128, 96);
$metadata['hwstring_small'] = "height='$uheight' width='$uwidth'";
// Make the file path relative to the upload dir
$metadata['file'] = _wp_relative_upload_path($file);
$sizes = ajax_thumbnail_rebuild_get_sizes();
$sizes = apply_filters( 'intermediate_image_sizes_advanced', $sizes );
foreach ($sizes as $size => $size_data ) {
if( isset( $thumbnails ) && !in_array( $size, $thumbnails ))
$intermediate_size = image_get_intermediate_size( $attachment_id, $size_data['name'] );
else
$intermediate_size = image_make_intermediate_size( $file, $size_data['width'], $size_data['height'], $size_data['crop'] );
$repeat = array( $attachment_id, $file, $thumbnails );
if ($intermediate_size)
$metadata['sizes'][$size] = $intermediate_size;
}
// fetch additional metadata from exif/iptc
$image_meta = wp_read_image_metadata( $file );
if ( $image_meta )
$metadata['image_meta'] = $image_meta;
}
return apply_filters( 'wp_generate_attachment_metadata', $metadata, $attachment_id );
if ( $repeat )
wp_generate_attachment_metadata_custom( $repeat[0], $repeat[1], $repeat[2] );
}
Thread Starter
jnz31
(@jnz31)
or maybe like so?? i’m not a hardcore php dev guy, but this one could work, too:
(if image_make_intermediate_size set meta, breakout and repeat)
removed, since it caused server error 500..
Thread Starter
jnz31
(@jnz31)
nope. all of the above is crap, but this one works for me:
make_meta and than grab the rest and add it to the meta array. not very beautiful, but a working start..
function wp_generate_attachment_metadata_custom( $attachment_id, $file, $thumbnails = NULL ) {
$attachment = get_post( $attachment_id );
$metadata = array();
if ( preg_match('!^image/!', get_post_mime_type( $attachment )) && file_is_displayable_image($file) ) {
$imagesize = getimagesize( $file );
$metadata['width'] = $imagesize[0];
$metadata['height'] = $imagesize[1];
list($uwidth, $uheight) = wp_constrain_dimensions($metadata['width'], $metadata['height'], 128, 96);
$metadata['hwstring_small'] = "height='$uheight' width='$uwidth'";
// Make the file path relative to the upload dir
$metadata['file'] = _wp_relative_upload_path($file);
$sizes = ajax_thumbnail_rebuild_get_sizes();
$sizes = apply_filters( 'intermediate_image_sizes_advanced', $sizes );
foreach ($sizes as $size => $size_data ) {
if( isset( $thumbnails ) && !in_array( $size, $thumbnails )) :
$intermediate_size = image_get_intermediate_size( $attachment_id, $size_data['name'] );
else :
$intermediate_size = image_make_intermediate_size( $file, $size_data['width'], $size_data['height'], $size_data['crop'] );
$intermediate_meta = image_get_intermediate_size( $attachment_id, $size_data['name'] );
endif;
if ( $intermediate_size && $intermediate_meta ) :
$metadata['sizes'][$size] = $intermediate_size;
$metadata['sizes'][$size]['path'] = $intermediate_meta['path'];
$metadata['sizes'][$size]['url'] = $intermediate_meta['url'];
elseif ($intermediate_size) :
$metadata['sizes'][$size] = $intermediate_size;
endif;
}
// fetch additional metadata from exif/iptc
$image_meta = wp_read_image_metadata( $file );
if ( $image_meta )
$metadata['image_meta'] = $image_meta;
}
return apply_filters( 'wp_generate_attachment_metadata', $metadata, $attachment_id );
}