Articles of cropping

Confusion about arguments sent to add_image_size

Looking at the documentation for Cropping Thumbnails when adding new image-sizes makes me confused. Set the image size by cropping the image and defining a crop position: add_image_size( ‘custom-size’, 220, 220, array( top, left ) ); // Hard crop top left When setting a crop position, the first value in the array is the x […]

How to upload multiple images on frontend to ACF gallery using update_field

I’m trying to save images submitted on a frontend form in a way that they are accessible via the ACF backend. In how to upload an image on ACF with update_field on wordpress, someone provided a solution for a single image upload (and consequently a single ACF image field). I thought it should be pretty […]

Generated media have incorrect aspect ratio

Uploaded an image via standard ‘add new’ dialog to the WordPress Media library. Here were the original Media Settings: Thumbnail – 150×150 Medium – 300×300 Large – 1024×1024 I uploaded a 650×144 image. Resulting generated image sizes: 150×144.jpg 300×66.jpg 336×144.jpg Only the medium image has the correct ratio. The other two images are basically a […]

Crop image from get_theme_mod Customizer field

I’m using the following code to allow a user to upload a custom image (in addition to header image) through the customizer. Is there a way to crop the image when displaying it? $wp_customize->add_setting( ‘intro-img’, array ( ‘default’ => ‘http://example.com/image.png’, ) ); $wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, ‘intro-img’, array( ‘label’ => ‘Intro Image’, ‘section’ => ‘section_one’, […]

Cropped thumbnail still displaying as full image

Steps to reproduce… 1) Add to functions.php: add_image_size( ‘half-size’, 200, 200, false ); 2) Add to template file (inside loop): <a href=”<?php the_permalink(); ?>” title=”<?php the_title_attribute(); ?>” > <?php the_post_thumbnail (‘half-size’, array(‘class’ => ‘profile_image’)); ?> </a> 3) Go to media library and add image to post gallery. Then crop image, click “thumbnail” radio button and […]

How to crop image from center using wp_image_editor

I am working on WordPress plugin. In plugin the user upload images from meta field and in back end i use wp_image_editor for cropping and re sizing the images. The images re sized very well but on cropping the images not cropped very well. I give x-dimension 100 and y-dimension 0. $resize_img = wp_get_image_editor( $wpc_prod_img[‘wpc_resize_img’] […]

the_post_thumbnail scaling not hard cropping

Lately I wanted to upgrade my blog with featured images/post thumbnails. I’m using a custom theme build on the roots theme (this is not a roots theme issue, I believe). The image I upload is 1024×768 and shall be cropped to letterbox format 1024×512. This is the code I’m using in the theme-file: <?php if […]

Custom image size not regenerating when image editted

I have a custom image size at 200×150 that works fine in a plugin I’m working on. Uploading new files is no problem but when I edit an image, the default image sizes get regenerated but my custom size does not. Is there a way to force the regeneration programatically in a filter or something?

Why can't I edit certain images from the WordPress Media library?

I’ve noticed some bizarre behaviour in my WordPress installation. For some photos, when I click “Edit Image”, the full image is not displayed to me – just the area visible in the thumbnail. And yet, if you click “View Image”, you can see the full image is actually there. Clearly, some manual intervention is required […]

Custom image size / thumbnail – Crop to aspect ratio even when source image is smaller than set dimensions

Normally when you set a custom image size using hard crop – e.g. add_image_size( ‘custom-size’, 400, 400, true ); – you get the following results: #1 Uploaded image: 600×500 > Thumbnail: 400×400. #2 Uploaded image: 500×300 > Thumbnail: 400×300. #3 Uploaded image: 300×200 > Thumbnail: 300×200. However what I’d like to do is when the […]