Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

What I am looking for is similar to a couple other questions. The links are:

Creating an Image-Centric Custom Post Type?

Using Default WordPress Custom Header Image Crop Feature in a Post Type / MetaBox

I am looking for a sort of combination of the two. I'll explain so you don't have to look up these other questions.

I would like a user to be able to upload a picture into a custom post type and be prompted to crop the image with a set aspect ratio before saving. I am trying to keep users from needing to crop images outside WordPress just to make them fit into a slideshow with a set image size.

The custom header functionality is pretty much what I'd like to use, but I am at a loss on how to pull that into either a plugin or a theme and have it execute in a custom post type. The fact that the user is asked to crop the image at a set ratio before proceeding is key.

I am fairly comfortable with custom post types if anyone can just give me a pointer on how to get WordPress to force a custom cropping of an image before saving the custom post.

Thanks in advance to whichever one of you coding geniuses knows/figures out how to do this.

share|improve this question

1 Answer 1

Don,

You will have to add support for thumbnails in your functions.php/plugin-file.php

//Add Support for Thumbs
if ( function_exists( 'add_theme_support' ) ) {
  add_theme_support( 'post-thumbnails' );
        set_post_thumbnail_size( 960, 276, true ); // default Post Thumbnail dimensions   
}
//Add Thumbnail sizes   
if ( function_exists( 'add_image_size' ) ) { 
  add_image_size( 'large-thumb', 960, 276, true ); //960 pixels wide x 276 height and cropping
  add_image_size( 'medium-thumb', 605, 174 ); //No crop
  add_image_size( 'small-thumb', 288, 83, true ); 
}

From here you can modify this output in your loop to work for your needs:

<?php if ( has_post_thumbnail() ) {

          echo '<a href="' . get_permalink( $post->ID ) . '" title="' . esc_attr( $post->post_title ) . '">';
          echo get_the_post_thumbnail($thumbnail->ID, 'small-thumb', array( 'alt' => esc_attr( $post->post_title ), 'title' => esc_attr( $post->post_title ) ));
          echo '</a>';  //Change the 'small-thumb' to whichever size you would like.
          } 

Hope this helps you figure out what you're doing - if you need any help building a Query for this I you should look into this page.

share|improve this answer
2  
Thanks for trying to answer David, but the point of the question was not how to get WordPress to crop or resize an image. It was to prompt the user to do so. To see what I mean, fire up the Twenty Ten theme and add a custom header image. You'll be prompted to crop the image to a given ratio. That is what I want for my custom post type. –  Don May 10 '12 at 5:29

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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