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.

So I know about setting custom images with add_image_size('name',X,Y,Crop?) which is cool but I need to build something that will crop images, regardless of their size, into squares.

Basically, I want to make sure the user's uploaded images will always be squares.

share|improve this question

1 Answer 1

I think a lot of theme development is getting away from using add_image_size because WordPress makes way to many images. So rather than doing it that way, you can use a plugin or even a plugin that will integrate into your theme. Here is a good one that is easy to use

https://github.com/sy4mil/Aqua-Resizer

I think this is a better way to go than doing the add_image_size. from the script, you just call whatever size and shape you will need.

For example. Lets say you need an image that is 125 x 125 which would give you a nice square. You could do something like this inside the loop.

 $thumb = get_post_thumbnail_id();
 $img_url = wp_get_attachment_url( $thumb,'full' ); //get full URL to image (use    "large" or "medium" if the images too big)
 $image = aq_resize( $img_url, 125, 125, true ); //resize & crop the image

 ?>

 <article <?php post_class()?> id="post-<?php the_ID(); ?>">

<?php if($image) : ?>
    <img src="<?php echo $image ?>"/>
<?php endif; ?>

That would take the featured image of the post and crop the image into a 125 x 125 sqaure and echo out the image.

You can see more examples on this page

share|improve this answer
    
I dont think that's going to work dor me. We are building a child theme for genesis so we have to use their hooks. Also, if I'm reading this right, that plugin requires that each image get manipulated manually. –  rugbert Mar 28 '13 at 21:21
    
That plugin can be easily integrated into your theme. You upload the folder and use and include in the function.php file. It doesn't have to be a plugin. –  Jamie Mar 28 '13 at 22:11
    
It still doesnt help me tho, it looks like I would have to manually adjust each image. And even if it didnt, what Im trying to do to crop all uploaded images into squares regardless of their size. This script looks like it adjusts each image manually, and with a set height and width. –  rugbert Mar 29 '13 at 13:23
    
well then maybe I don't understand what you are talking about. When you put in this plugin, you would replace the featured image with a call to the aq_resize function instead. So every image uploaded by the uploader would automatically be resized to whatever size you tell it. Like so aq_resize(510, 256); You would have to do the same thing with the featured image because you would have to call every image size that you created with add_image_size. Maybe you should add more information in your question so it makes more sense. This script resizes each image on the fly. –  Jamie Mar 29 '13 at 17:06
    
Answers should be more than plain links. They should actually be an answer instead of a route where someone will maybe find an answer. Please help preventing link rot, edit your answer and provide the needed information that helps the OP as well as later visitors to solve their problem. –  kaiser Mar 17 at 11:33

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.