Hallo zusammen,
das ist mein erster Post. Habt bitte etwas Geduld, falls ich im falschen Forum gelandet bin oder unverständlich schreibe.
Ich verwende WP 3.9.1
Zu meinem Problem:
Ich habe ein Plugin geschrieben in dem ich mit folgendem Codeschnipsel weitere Bildgrößen hinzugefügt habe.
add_theme_support( 'post-thumbnails' );
$my_image_sizes = array(
array( 'name'=>'featuredImageTop', 'width'=>976, 'height'=>325, 'crop'=>true ),
array( 'name'=>'featuredImageArticle', 'width'=>300, 'height'=>300, 'crop'=>true )
);
// For each new image size, run add_image_size() and update_option() to add the necessary info.
// update_option() is good because it only updates the database if the value has changed. It also adds the option if it doesn't exist
foreach ( $my_image_sizes as $my_image_size )
{
add_image_size( $my_image_size['name'], $my_image_size['width'], $my_image_size['height'], $my_image_size['crop'] );
update_option( $my_image_size['name']."_size_w", $my_image_size['width'] );
update_option( $my_image_size['name']."_size_h", $my_image_size['height'] );
update_option( $my_image_size['name']."_crop", $my_image_size['crop'] );
}
// Hook into the 'intermediate_image_sizes' filter used by image-edit.php.
// This adds the custom sizes into the array of sizes it uses when editing/saving images.
add_filter( 'intermediate_image_sizes', 'my_add_image_sizes' );
function my_add_image_sizes( $sizes )
{
global $my_image_sizes;
foreach ( $my_image_sizes as $my_image_size )
{
$sizes[] = $my_image_size['name'];
}
return $sizes;
}
Alles anzeigen
Wenn ich jetzt ein Bild (Dateiname wp-logo.jpg) hochlade und bearbeite, also zum Beispiel einen Teil ausschneide und speichere, werden auf dem Filesystem meine neuen Bildgröße automatisch erzeugt.
Zum Beispiel "wp-logo-e1399997316307-976x325.jpg"
Jetzt zu meinem Problem:
Skaliere ich dieses Bild und drücke auf Speichern, werden meine neuen Bildgrößen allerdings nicht erzeugt.
Ich habe die betroffene Stelle auch im Core gefunden. (/wp-admin/includes/image-edit.php)
if ( 'nothumb' == $target || 'all' == $target || 'full' == $target || $scaled )
{
$tag = false;
if ( isset($backup_sizes['full-orig']) ) {
if ( ( !defined('IMAGE_EDIT_OVERWRITE') || !IMAGE_EDIT_OVERWRITE ) && $backup_sizes['full-orig']['file'] != $path_parts['basename'] )
$tag = "full-$suffix";
} else {
$tag = 'full-orig';
}
if ( $tag )
$backup_sizes[$tag] = array('width' => $meta['width'], 'height' => $meta['height'], 'file' => $path_parts['basename']);
$success = update_attached_file( $post_id, $new_path );
$meta['file'] = _wp_relative_upload_path( $new_path );
$size = $img->get_size();
$meta['width'] = $size['width'];
$meta['height'] = $size['height'];
if ( $success && ('nothumb' == $target || 'all' == $target) ) {
$sizes = get_intermediate_image_sizes();
if ( 'nothumb' == $target )
$sizes = array_diff( $sizes, array('thumbnail') );
}
$return->fw = $meta['width'];
$return->fh = $meta['height'];
} elseif ( 'thumbnail' == $target ) {
$sizes = array( 'thumbnail' );
$success = $delete = $nocrop = true;
}
Alles anzeigen
Hier wird in Zeile 728 abgefragt, ob die Variable $scaled true ist. Weiter unten in Zeile 747 fehlt allerdings die Abfrage auf diese Variable. Dies hat zur Folge, dass die Variable $sizes nicht befüllt wird. Dadurch werden weiter unten auch nicht meine neuen Bildgrößen erzeugt.
Hab ich irgendwas vergessen oder ist das wirklich ein Bug?
Vielen Dank für eure Hilfe!
Marcus