28

Here's an improvement that uses the settings as you tried to do: add_image_size('medium', get_option( 'medium_size_w' ), get_option( 'medium_size_h' ), true );


20

The add_image_size( $name, $width, $height, $crop ) function is graceful enough to handle multiple calls using the same $name. It simply overwrites the existing value: $_wp_additional_image_sizes[$name] = array( 'width' => absint( $width ), 'height' => absint( $height ), 'crop' => (bool) $crop ); So that means that all you need to do to override ...


19

You can use the native Wordpress image_resize function to scale up images. Wordpress provides a hook called "image_resize_dimensions" which you can use to overwrite the default cropping settings. Here is a modified function which will support scaling up: function image_crop_dimensions($default, $orig_w, $orig_h, $new_w, $new_h, $crop){ if ( !$crop ) ...


18

You can over write the default like this: add_image_size( 'medium', 200, 200, true );


13

Intermediate image generation is extremely rigid. image_resize() keeps it close to code and completely lacks hooks. Pretty much only option for this is to hook into wp_generate_attachment_metadata and overwrite WP-generated image with your own (which will need bit of a image_resize() fork). I need this for work so I might be able to share some code later. ...


12

Take a look at Otto's Dynamic Image Resizer plugin This plugin changes the way WordPress creates images to make it generate the images only when they are actually used somewhere, on the fly. Images created thusly will be saved in the normal upload directories, for later fast sending by the webserver. The result is that space is saved (since images ...


12

This has always been a bugbear for me - the lack of on-demand image sizing, and the subsequent number of files you can end up with if you have lots of sizes! I can see the logic behind your efforts - the trouble is, add_image_size only truly comes into play at point-of-upload. As such, is_page_template(..) will always be false. A quick google dug up Aqua ...


12

Problem solved - the image width was being limited by $content_width set to 640 in the functions.php file included with Bones WP theme. Hopefully this information will help anyone else struggling with similar problems.


11

have you tried, if(has_post_thumbnail()) { $image_src = wp_get_attachment_image_src( get_post_thumbnail_id(),'full' ); echo '<img src="' . $image_src[0] . '" width="100%" />'; }


11

A very special filter The jpeg_quality filter is a really special one: It gets used in three different cases and you've to use the second argument to determine, if you want to use the filter or not. Don't let it do everything The main problem for such a special filter is, that it may fire for later actions, if you ain't remove it - allow it to run after ...


11

The Approach I think the best approach is to create an image size "on the fly", just before the images is resized. You can do that using 'intermediate_image_sizes_advanced' filter hook. That allows you to edit the size to be generated, but being aware of the current image size, that is stored in the array $metadata passed by the filter as second argument. ...


10

Wordpress codex has the answer, its below. Set the image size by cropping the image and defining a crop position: add_image_size( 'custom-size', 220, 220, array( 'left', 'top' ) ); // Hard crop left top When setting a crop position, the first value in the array is the x axis crop position, the second is the y axis crop position. ...


9

I found a plugin that does this for me: Additional image sizes (zui) When you delete an image size that size will not be created for all NEW images you upload. However, images created for deleted sizes still exist on the server as well as the image attachment metadata for those sizes. This feature will physically delete those images from the server ...


9

Gee, I keep solving my own problems all the time. Here's how I solved it in the end. I discovered that add_image_size does not ignore the identical dimensions of the image size, but instead points the file name towards the same file in the uploads dir. Once I knew that, I could just save the grayscale image under a different name, return that name to the $...


9

The srcset attribute is constructed from images that are the same aspect ratio. Create a few of those and you'll be ok. add_image_size( 'compare-offer-box', 400, 300, true); add_image_size( 'compare-offer-box-2', 800, 600, true); add_image_size( 'compare-offer-box-3', 1200, 900, true); for example. The fourth, boolean, argument tells WP to crop to the ...


8

A quick and easy fix for this is to make use of a plugin called Force Regenerate Thumbnails (to which I don't have any affiliation to) Unlike a plugin like Regenerating Thumbnails, Force Regenerate Thumbnails creates all your new custom sizes and delete all redundant/orphaned sizes. Force Regenerate Thumbnails allows you to delete all old images size ...


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

I have developed a solution to this problem that does not require hacking the core: http://bradt.ca/archives/image-crop-position-in-wordpress/ I have also submitted a patch to core: http://core.trac.wordpress.org/ticket/19393 Add yourself as a Cc on the ticket to show your support for it to be added to core.


7

No, that seems to work right. You could test it by doing <?php echo get_the_post_thumbnail('grade-image'); ?> try this. add_image_size( "grade-image", 320, 300, true ); add_filter( 'image_size_names_choose', 'my_custom_sizes' ); function my_custom_sizes( $sizes ) { return array_merge( $sizes, array( 'grade-image' => __('Grade Image')...


7

You can use get_attached_file() to: Retrieve attached file path based on attachment ID. And get_post_thumbnail_id() to determine the post thumbnail of the current post, or any post if you set the $post_id parameter. Exemplary usage: $bytes = filesize( get_attached_file( get_post_thumbnail_id() ) ); Use size_format() to Convert a ...


7

That's easy! If you have SSH access, log in and do the following for each size. I am just showing 150x150 size only. Go to the desired uploads folder via command line. cd /your-site.com/wp-content/uploads Let's find if that size is available. find ./uploads/* -iname '*-150x150.*' -ls If you see some images as the output then delete 'em with find ./...


6

Put this in your theme functions file. It will stop Wordpress from creating anything but the 3 default sizes when uploading. When an image is then requested in a particular size, which is not yet generated, it will be created only that once. add_filter('image_downsize', 'ml_media_downsize', 10, 3); function ml_media_downsize($out, $id, $...


6

I was able to solve it using the following code: function my_handle_upload ( $params ) { $filePath = $params['file']; if ( (!is_wp_error($params)) && file_exists($filePath) && in_array($params['type'], array('image/png','image/gif','image/jpeg'))) { $quality = 90; list($largeWidth, $...


6

This is more of a general srcset and browser question, not a WordPress specific question. However, in general, you can't predict what browsers will do with the srcset information. For your specific example, it appears that you failed to clear the cache completely between your reloads. Note the 304 response indicating that your browser already has the image ...


6

Some suggestions: If you want to try out the Image Editor API you can try to replace imagejpeg( $resource, $image, 35 ); with: $editor = wp_get_image_editor( $image ); if ( ! is_wp_error( $editor ) ) { $editor->set_quality( 35 ); $editor->save( $image ); } unset( $editor ); Also try to test e.g. these parts: $resource = ...


5

I believe those are probably generated by the default WordPress sizes - thumbnail, medium and large. (See Appearance > Media for where those sizes are set). If you want to eliminate the extra image sizes the simplest way might be to eliminate some of your theme's custom image sizes and use the defaults instead. OR, you can "unset" the defaults. This ...


5

If those are the default alternate sizes, you don't need any code to do this. To get rid of the default alternate sizes, just go to Settings > Media in the admin, and set the sizes for "Thumbnail", "Medium" and "Large" to 0px by 0px. Once you save these settings, WordPress will no longer create the alternate sizes (unless additional sizes are specified in a ...


5

If you want WordPress to hard-crop the images to those absolute image dimensions, you can set the $crop argument of add_image_size to true, by default it is false: add_image_size( 'thumbnail-small', 179, 147, true );


5

Disclaimer: - This isn't actually an answer. - It is intended to help you with your additional research on the topic. - Furthermore it is reflecting a - at least felt - lately more frequent occurrence of similar questions regarding similar problems. Additional information regarding this topic on Wordpress Development: Removing Image Sizes for Custom ...


5

If you want get_post_gallery_images to give you full size images, you can use the following: // Use full size gallery images for the next gallery shortcode: add_filter( 'shortcode_atts_gallery', 'wpse_141896_shortcode_atts_gallery' ); // Your code: $gallery = get_post_gallery_images( $post ); foreach ($gallery as $img) { ?> <li><img src="&...


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