Disable Aspect Ratio Crop on Custom Header Image

3.3k views Asked by At

Hey Guys, I'm building a WordPress theme that let's a user upload a custom image header using the built in WordPress functions.

I have this set in my functions.php file:

define( 'HEADER_IMAGE_WIDTH', apply_filters( 'basic_header_image_width', 500 ) );
define( 'HEADER_IMAGE_HEIGHT', apply_filters( 'basic_header_image_height', 150 ) );

And when a user uploads a new image, they are forced to crop the image to maintain the 150x500 aspect ratio. What I think it should do is allow the user to crop the image, as long as it fits within a 500x150px box.

Is this possible? If not, I'd rather turn off the cropping feature all together.

Thanks, Drew

2

There are 2 answers

0
ott On

I just change the crop numbers to what the Image pixels are. so

define( 'HEADER_IMAGE_WIDTH', apply_filters( 'basic_header_image_width', 500 ) );
define( 'HEADER_IMAGE_HEIGHT', apply_filters( 'basic_header_image_height', 150 ) );

would be

define( 'HEADER_IMAGE_WIDTH', apply_filters( 'basic_header_image_width', 1060 ) );
define( 'HEADER_IMAGE_HEIGHT', apply_filters( 'basic_header_image_height', 240 ) );

and I have no issues with it as far as I've seen, so if you set it to like 2000 and 2000 they should be able to upload nearly anything

2
Prusprus On

I've fallen across this question while I've been trying to customize the crop feature of wordpress. So far, the only way I've found to set restraints on the crop is to find the javascript that initializes the crop and define the restraints (or 'options') there. The file can be found in wp-admin/js/image-edit.js (have a look at image-edit.dev.js aswell, it's not min'd so easier to understand).

Add your options at the .imgAreaSelect() function call.