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 Original File (not-...


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

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

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


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


4

A majority of the answers covered how to stop creating future default image sizes but this doesnt account for creating any custom sizes in your theme but here is another solution to add to functions.php: function wpse_240765_unset_images( $sizes ){ unset( $sizes[ 'thumbnail' ]); unset( $sizes[ 'medium' ]); unset( $sizes[ 'medium_large' ] ); ...


4

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


4

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


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

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

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

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


3

You can easily delete files using "find" command on linux, just needed to do the same thing. You can run the following in bash console: cd /var/www/wordpress/wp-content/uploads find -type f -regex '.*[0-9]+x[0-9]+.\(jpg\|png\|jpeg\)$' -delete


3

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


3

I solved this installing 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


2

For all the people who've: registered the sizes in their functions.php set them in a callback for after_setup_theme with the add_action function installed Regenerate Thumbnails installed php5_gd and restarted the server You may have to manually configure the loading of the extension, if it wasn't for you. First, check if GD is actually enabled as an ...


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

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


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

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


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

No idea, how to remove existing images. But you can stop generating image sizes for new images you are going to upload. If you like to write codes: Place this code snippet in your theme's functions.php file- add_filter( 'intermediate_image_sizes_advanced', 'wpse_240765_image_sizes' ); function wpse_240765_image_sizes( $sizes ){ $sizes = array(); ...


2

If coding is not your strongest point you may want to look at a plugin solution. What I have in mind is a suggestion of a couple free plugins residing in the WordPress repository: Media Cleaner by Jordy Meow Optimize Images Resizing by OriginalEXE Thumbnail Cleaner I must admit that I have not yet used the first one - Media Cleaner - so I cannot provide ...


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

For the record since I ended up here when experiencing the same issue on my localhost: In php.ini, Uncomment the line with: extension=php_gd2.dll Restart apache / all services This sorted it out for me (I may have switched a few other services on while I was there, but I believe this is what fixed it!)


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


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