my client asked me to create gallery(WP gallery) based on this site.

the problem here is that i need to crop images based on image size before inserting the image in the Media library.

now i using this code to check the image width and height:

function validate_image_size( $file ) {

$image = getimagesize($file['tmp_name']);
$image_width = $image[0];
$image_height = $image[1];

if ($image_width > $image_height) {
// crop to horizontal

if ($image_height > $image_width) {
// crop to vertical
  1. how can i crop image to horizontal or vertical?

  2. how can i show all images after crop based on the order of this site: site

always 2 vertical images in line or horizontal on line?

  • some one can help?
    – need-help
    Commented Jan 28, 2015 at 14:46

1 Answer 1


why didn't use add_image_size( 'horizontal_img', 800, 300, true ); add_image_size( 'vertical_img', 300, 800, true );

And then $image_hor = wp_get_attachment_image_src($post_id,'horizontal_img'); $image_ver = wp_get_attachment_image_src($post_id,'vertical_img');

when echo $image_hor[0] you will get your desire sized image url.

Thanks Musa

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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