0

Finding documentation on wp.media is really tough, so bear with me.

I'm creating a metabox to attach images to a custom post type. I'm able to get a media frame to open, have it accept uploads, and return the uploaded attachment ID.

However, images uploaded through my wp.media frame do not have image sizes generated for them. Is there a way to have them automatically generated? If not, what is a good approach for generating them manually?

My wp.media call looks something like:

jQuery(function($){
  $(".metabox-image").each(function(){
    var metabox = $(this);
    var input = $(".metabox-image-value", metabox);
    var frame;

    var openFrame = function() {
      if (!frame) {
        frame = wp.media({
          // Only show images that have been uploaded to this post
          library: {
            type: "image",
            uploadedTo : wp.media.view.settings.post.id
          }
        });

        frame.on("select", function(){
          var att = frame.state().get("selection").first().toJSON();
          input.val(att.id);
        });
      }

      frame.open();
    };

    $(".metabox-image-select-button", metabox).on("click", function(e){
      e.preventDefault();
      openFrame();
    });
  });
});

In my save_post action I simply save the attachment ID in a post_meta field. Later, when I use wp_get_attachment_image_src( $attachment_id, 'thumbnail' ) only a URL to the full-size image is returned.

0

Verify that the "GD" php library is enabled. You can do so by adding phpinfo(); to one of your php templates and then search the result for GD or GD Support.

The GD library is used for image manipulation and resizing is one of those functions.

To enable GD on windows you can edit the php.ini file in your php installation and uncomment the php_gd2.dll extension:

; Windows Extensions
; Note that ODBC support is built in, so no dll is needed for it.
; Note that many DLL files are located in the extensions/ (PHP 4) ext/ (PHP 5)
; extension folders as well as the separate PECL DLL download (PHP 5).
; Be sure to appropriately set the extension_dir directive.
;
;extension=php_bz2.dll
;extension=php_curl.dll
;extension=php_fileinfo.dll
extension=php_gd2.dll ; <-- THIS ONE
;extension=php_gettext.dll

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.