Make WordPress Core

Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#31228 closed defect (bug) (invalid)

The "+" character in add_image_size breaks wp_get_attachment_image

Reported by: ashorlivs's profile ashorlivs Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.1
Component: Media Keywords: reporter-feedback
Focuses: Cc:

Description

If one adds an image size which name contains the "+" character, wp_get_attachment_image will return de base image instead of the resized image.

var_dump( wp_get_attachment_image( $attachment_id, 'full');
// ... /elaenia.jpg (1200 × 797)

add_image_size( 'test + image', 121, 135, true );
var_dump( wp_get_attachment_image( $attachment_id, 'test + image');
// ... /elaenia.jpg (1200 × 797)

add_image_size( 'test - image', 121, 135, true );
var_dump( wp_get_attachment_image( $attachment_id, 'test - image');
// ... /elaenia-121x135.jpg (121 x 135)

Tested with Apache 2.4 in WP 4.1.

Simply changing "+" with another character solves the issue.

Change History (5)

#1 @joemcgill
9 years ago

  • Keywords reporter-feedback added

Hi ashorlivs,

I can't reproduce this error on WP 4.1. Can you try dumping the metadata for an image you upload after adding the image sizes? Something like this:

$meta = wp_get_attachment_metadata( $id );
var_dump($meta);

You should see an array of sizes available for the image by passing the image's ID to wp_get_attachment_metadat(). One of them should look something like this:

'test + image' => 
        array (size=4)
          'file' => string 'elaenia.jpg-121x135.jpg' (length=32)
          'width' => int 121
          'height' => int 135
          'mime-type' => string 'image/jpeg' (length=10)

#2 @ashorlivs
9 years ago

Hi Joe,
here's a dump:

array(5) {
  ["width"]=>
  int(500)
  ["height"]=>
  int(481)
  ["file"]=>
  string(45) "2015/02/4b678e6675f1613431a876086766d29a.jpeg"
  ["sizes"]=>
  array(27) {
    ["thumbnail"]=>
    array(4) {
      ["file"]=>
      string(45) "4b678e6675f1613431a876086766d29a-150x150.jpeg"
      ["width"]=>
      int(150)
      ["height"]=>
      int(150)
      ["mime-type"]=>
      string(10) "image/jpeg"
    }
    ["medium"]=>
    array(4) {
      ["file"]=>
      string(45) "4b678e6675f1613431a876086766d29a-300x289.jpeg"
      ["width"]=>
      int(300)
      ["height"]=>
      int(289)
      ["mime-type"]=>
      string(10) "image/jpeg"
    }
    ["News - Bloc 2 - Full image"]=>
    array(4) {
      ["file"]=>
      string(45) "4b678e6675f1613431a876086766d29a-319x135.jpeg"
      ["width"]=>
      int(319)
      ["height"]=>
      int(135)
      ["mime-type"]=>
      string(10) "image/jpeg"
    }
    ["News - Bloc 2 - Image et texte"]=>
    array(4) {
      ["file"]=>
      string(44) "4b678e6675f1613431a876086766d29a-92x135.jpeg"
      ["width"]=>
      int(92)
      ["height"]=>
      int(135)
      ["mime-type"]=>
      string(10) "image/jpeg"
    }
    ["News - Bloc 2 - Image + texte"]=>
    array(4) {
      ["file"]=>
      string(37) "4b678e6675f1613431a876086766d29a.jpeg"
      ["width"]=>
      int(500)
      ["height"]=>
      int(841)
      ["mime-type"]=>
      string(10) "image/jpeg"
    }
  }
  ["image_meta"]=>
  array(11) {
    ["aperture"]=>
    int(0)
    ["credit"]=>
    string(0) ""
    ["camera"]=>
    string(0) ""
    ["caption"]=>
    string(0) ""
    ["created_timestamp"]=>
    int(0)
    ["copyright"]=>
    string(0) ""
    ["focal_length"]=>
    int(0)
    ["iso"]=>
    int(0)
    ["shutter_speed"]=>
    int(0)
    ["title"]=>
    string(0) ""
    ["orientation"]=>
    int(0)
  }
}

Same with:

var_dump( wp_get_attachment_image_src( 594, 'News - Bloc 2 - Image + texte'));

My add_image_size are placed in a custom plugin instead of a theme, and I'm using the Advanced Custom Forms plugin. Hope it helps!

#3 @joemcgill
9 years ago

It looks like WordPress is saving the data for the custom size named 'News - Bloc 2 - Image + texte', but the file name is incorrect. I'm not able to reproduce this problem using the same size name so it may be a problem with your setup.

Can you try reproducing the same error using a default theme with plugins turned off by placing the add_image_size() function in your functions.php file? If you upload the image directly into the media library and the problem goes away, it's likely to be a bug in your plugin or in ACF. If the problem persists, then we can dig further.

#4 @ashorlivs
9 years ago

  • Keywords close added
  • Resolution set to invalid
  • Status changed from new to closed

Fresh install with no plugin and theme 2015 is fine with add_image_size('News - Bloc 2 - Image + texte', 250).

I had no idea this problem could come from a plugin since I thought resizing and outputing was native and unaltered by external code.

Sorry for the false flag, thanks for your help anyway @joemcgill !

#5 @DrewAPicture
9 years ago

  • Keywords close removed
  • Milestone Awaiting Review deleted
Note: See TracTickets for help on using tickets.