9

WordPress by default is designed to generate 3 types of cropping of any uploaded images (Media): Thumbnail (typically 150px × 150px) Medium (typically 300px × 300px) Large (typically 1024px × 1024px) It's to ensure site speed with different sizes where necessary. So, with uploading the Original image there would be at least 4 files- The ...


8

WordPress "crop" doesn't literally mean crop. As in take an image and cut out this precise portion of it from specified point. What it roughly means is: resize image to fit as well as possible, then crop parts that don't fit. In effect this meant that results are affected by ratio both of source image and target size. The exact logic is contained in ...


7

In your theme's functions.php file: /* register new image size * 200px wide and unlimited height */ add_image_size( 'wpse73058', 200, 9999, false ); In a template or the like: if ( has_post_thumbnail() ) { the_post_thumbnail( 'wpse73058' ); }


7

Yes, WordPress resizes & crops all images depending on what your theme defined as @Gerard already explained in his answer. So the last boolean argument for add_image_size() is to crop or not. Note that this doesn't define the crop position. To alter that behavior look at this answer for example. What happens inside core? As you've already seen in the ...


6

Unsetting sizes can normally be done easily via intermediate_image_sizes_advanced hook. The only problem is, there is only the $sizes array available, so this sufficient for a general level, but not if you want to do this conditionally. The information needed to do it conditionally can be gathered with debug_backtrace - debug_backtrace is performance-wise ...


4

Per the Codex entry for the_post_thumbnail(), passing an array has not worked since WordPress 3.0: PLEASE NOTE: The crop does not work in WP 3.0+. All that is needed for WP 3.0+ is the call for the thumbnail to post. Then proceed to media in the dashboard and set your thumbnail to crop to the size you wish to use. The correct implementation is to create ...


3

As @PieterGoosen said, your point is valid. A look into the source confirms that the codex description of add_image_size was wrong there. It was, because I changed it to be correct. That said, everyone can help improving the codex, you just need to register. You might want to take a look at Contributing to WordPress for a introduction on how to do that, the ...


3

To regenerate custom image size when image is edited in image editor , You have to add following options in wp_options table using update_option function along with add_image_size. Example : $img_size_name = 'custom-size'; // The new image size name. if ( function_exists( 'add_theme_support' ) ) add_image_size($img_size_name, 100, 100 , true); ...


3

Normally it is because a Wordpress theme uses the thumbnails on its code: in loops, galleries, etc. It is defined in the file functions.php: add_image_size( $name, $width, $height, $crop ); For example, like this: add_theme_support('post-thumbnails'); add_image_size('custom-thumbnail', 80, 80, true ); add_image_size('medium-thumbnail', 180, 120, true ); ...


3

Argh..easy to fix: instead of include( ABSPATH . 'wp-admin/includes/image.php' ); use require_once( ABSPATH . 'wp-admin/includes/image.php' ); Hope this helps someone!


3

They are not the same. In the 800x350 image, a little bottom is cropped. This is how the hard cropped work: First, it scales your image to match your image size. It can be width or height. Your size is 800x350 If your original image scaled according to 800px width has the 400px height (bigger than 350), 50px of the bottom will be cropped ( because you ...


3

It looks like the select and crop functionality is currently only used in the WordPress Customizer. However, after looking over the code in the Admin folder of WordPress I was able to get it working on my themes option page. Here is my setting for a header picture: function setting_heading_picture() { $heading_picture = esc_attr(get_option( '...


3

First use the code given by @Darren on any page. For simplicity I've combined PHP and JS code in single block: <?php $heading_picture = esc_attr(get_option( 'heading_picture' )); ?> <input type="hidden" name="heading_picture" id="heading_picture" value="<?php echo $heading_picture; ?>" /> <img id="heading_picture_preview" class="...


2

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' ...


2

If the above answer does not work, I believe you will need to make a modification in the theme functions file (functions.php). You should find either set_post_thumbnail_size or add_image_size. The functions take 3 and 4 parameters respectively but the last option should be a true or false and relates to cropping. e.g. add_image_size( 'news-image', 250, ...


2

Plugins and Themes can define their own thumbnail sizes. WordPress will convert all newly uploaded images to all registered size definitions.


2

If you pass true for the last $crop argument then so called "hard" crop mode is used. This will make WP produce results at exact size specified, except few edge cases (if image uploaded is smaller than specified size for example). Note that original image is still retained as is. If you need to actually modify originals as well — that is out of what WP ...


2

u can use this: function wpse128538_resize($url, $width, $height = null, $crop = null, $single = true) { //validate inputs if (!$url OR !$width) return false; //define upload path & dir $upload_info = wp_upload_dir(); $upload_dir = $upload_info['basedir']; $upload_url = $upload_info['baseurl']; //check if $img_url is local ...


2

Try this code $crop = array( 'center', 'center' ); $resize_img->resize( $wpc_image_width, $wpc_image_height, $crop);


2

You're right that it just doesn't work like that. If it's OK to think of your question the other way around though, you can get the right outcome in modern browsers using a selection of image sizes and responsive images. If you use code like this: add_image_size( 'custom-size-small', 200, 200, true ); add_image_size( 'custom-size-medium', 300, 300, true );...


2

This isn't a really good solution since it's a newer CSS solution and it's only working in 78.9% of users browsers, but there are a few polyfills that can overcome that object-fit-images and fitie img { display: block; overflow: hidden; width: 400px; height: 400px; -o-object-fit: cover; object-fit: cover; } Ideally it would be ...


2

By default, WordPress uses the GD Graphics Library to resize and crop images. On servers with limited resources however, GD fails on images with large file sizes. If you really need to keep the size of your images, but want to keep your file sizes down, consider processing your images first with tinypng.com. Their online compressor retains as much quality ...


2

WordPress does not create any thumbnail on the fly. If you try to fetch a size that doesn't exist, either the closest size or the full size image will be retrieved. The closest solution you can try is to fetch a size larger than what you want, and then size it down via CSS and crop it. Let's say the registered sizes are 50 x 150, 300 x 300 and 1024 x 1024, ...


2

No, there's not a way to do this by using the_post_thumbnail(), neither it's recommended. What you are looking for is cropping the images on the fly. This will cost heavy server resources, especially when you have a lot of images to work with. But in theory, to do so, you can make a script that takes an image as input, crops the image using PHP, and then ...


2

wp_get_attachment_image_src() function returns an array that's why your code isn't working. Try the following code. <a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home"> <?php if ( get_theme_mod( 'bwpy_logo2' ) ) : $img_data = wp_get_attachment_image_src( absint( get_theme_mod( 'bwpy_logo2' ) ) ); $img_url = ...


2

There is too little information to be completely sure, but usually this error occurs when WordPress cannot find the graphic library which should be installed on your server. So you should check with your provider to see if Imagick and/or GD are installed. You can also add this little snippet of code in your functions.php file to make sure WordPress looks ...


2

I solved this install the next library sudo apt-get install php5-gd -> for php5 sudo apt-get install php7.0-gd -> for php7 sudo apt-get install php7.2-gd -> for php7.2


1

wordpress by default do not resize/create/crop image for small images. It will show original image instead. For eg. required is 335x355. You uploaded image size 25x25 then it will not create image of 335x355 size. It will show full image i.e original image instead when you call 335x355 size image


1

To disable cropping, insert this below code in disable-automatic-image-crop.php file in your mu-plugins folder: <?php /* Plugin Name: Disable Automatic Image Crop Author: Wordpress Community Description: https://gist.github.com/czenzel/0f5888cbbfa4a857e56361dd3bc19b39 */ add_action( 'init', 'czc_disable_extra_image_sizes' ); add_filter( '...


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 ...


Only top voted, non community-wiki answers of a minimum length are eligible