Hot answers tagged

18

When an image is uploaded in WordPress, it is saved in its original size, and also as some resized copies in different sizes. In this way it becomes easy to use different sizes, of the same image, for different purposes. By default, WordPress creates 3 copies in 3 different sizes: 'thumb' 'medium' 'large' The size in pixels for these 3 sizes can be set ...


17

Add this code to your theme's functions.php file, and it will limit minimum image dimentions add_filter('wp_handle_upload_prefilter','tc_handle_upload_prefilter'); function tc_handle_upload_prefilter($file) { $img=getimagesize($file['tmp_name']); $minimum = array('width' => '640', 'height' => '480'); $width= $img[0]; $height ...


13

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


11

Philipp, anything is possible if you set your mind to it. You can solve your issue by extending the WordPress image editor class. Note I'm using WordPress 3.7 - I haven't checked any of the below code in earlier versions and in the latest 3.8 release. Image Editor basics WordPress has two built in classes that handle image manipulation: ...


10

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


10

Found it here. The answer is: global $_wp_additional_image_sizes; print '<pre>'; print_r( $_wp_additional_image_sizes ); print '</pre>';


9

I created two plugins that together should solve my needs. They are currently in an early alpha stage, and all comments are welcome. The base plugin is an On-Demand Resizer. This plugins monitors requests for non-existing files in the uploads dir, and creates images of the requested size if needed. For example, image-200x100.jpg will create and return ...


9

For post thumbnails you can either crop and image to the thumbnail size or scale the image. To enable crop you can call the thumbnail 1 of 2 ways. Name a size in the functions.php file like so: <?php add_image_size( 'my-post-thumbnail', 494, 168, true ); ?> and then call it in the theme file <?php the_post_thumbnail('my-post-thumbnail'); ...


8

The 'jpeg_quality' filter hook functions accept two arguments: $jpeg_quality and $function which is the function from within the filter hook is fired and can be either image_resize or wp_crop_image. So there is no way to selectively set the quality of .jpeg images according to image size from this filter hook function. However, you still can hook to a later ...


7

There are a few steps to this, as I found out today. First, you add a custom image size (you can put this somewhere the functions.php file in your theme): add_theme_support( 'post-thumbnails' ); add_image_size( 'my-size', 550, 550 ); // not sure what you want your height to // be, but this'll shrink it to 550px ...


7

I prefer not to reformat a colleague's code. So, this is almost the same answer as @MaorBarazany's, but checking the mime type, changing the file['error'] declaration and changing the function namespace to this wpse Question ID. Also, the check only occurs for users that are not administrators. add_action( 'admin_init', ...


6

May be this filter should work intermediate_image_sizes Note: This solution will work if you are uploading an image from post edit screen. (tested on localhost with WP-3.8.1) add_filter( 'intermediate_image_sizes', 'ravs_slider_image_sizes', 999 ); function ravs_slider_image_sizes( $image_sizes ){ // size for slider $slider_image_sizes = array( ...


6

Hi @jaredwilli: Dude! Valiant effort, and nice work. All-in-all it could be a great addition to WordPress. You were so close, but you had somewhere between 5 and 10 little failed assumptions or code that looks like you started it but didn't get back to it because it wasn't working. I reworked your function only as much as I needed to correct it. The ...


5

I asked a similar but broader question, and I still need to research and write a complete answer. In the meantime here are some pointers that might help you: I wrote a set of plugins that resizes all images to the size used in the editor. It works by converting <img src="image.jpg" width="200" height="400"/> to <img src="image-200x400.jpg" ...


5

No, wordpress can not resize BMP files. Beware that it does not make sense to use BMP files in a website because a broad number of webbrowsers is not able to display them. Filetypes that are supported by Wordpress and which are widely supported by internet browsers are: GIF, JPG and PNG. Those formats are optimized for internet use as they compress image ...


5

The issue is that WordPress always maintains the aspect ratio on your photos. For a lot of uses, this makes sense. However, if you're trying to line up a bunch of images — some in portrait, others in landscape — it can be a real pain. If you want to fix this, you can register a new image size in your functions.php file in your theme. For example, I just ...


5

I think the only solution you have at the moment is to disable all intermediate image sizes: add_filter( 'intermediate_image_sizes', '__return_empty_array', 99 ); And then manually generate them, depending on the post type, by hooking into 'wp_generate_attachment_metadata', where you do have access to the attachment id (and therefore to it's parent post): ...


5

I figured it out! In my php.ini file I had to uncomment extension=php_gd2.dll, then it started working after I rebuilt the images I uploaded :) Thanks, Josh


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

The defaults are Thumbnail 150x150, Medium 300x300, and Large 1024x1024. The fixed values can be changed in the admin dashboard under Settings > Media. You can also change them in your theme's functions.php: update_option( 'thumbnail_size_w', 160 ); // Set Thumbnail width - default 150 update_option( 'thumbnail_size_h', 160 ); // Set Thumbnail height - ...


5

Concerning documentation there is this blog post on the Make Blog: Responsive Images in WordPress 4.4 To increase the 1600px limit mentioned in the comments try this: add_filter('max_srcset_image_width', function($max_srcset_image_width, $size_array){ return 2000; }, 10, 2); Finally as already mentioned you should fix your calls to add_image_size ...


5

I want to disable the srcset only when calling a specific thumbnail size (for example only when calling full image size). Here are two ideas (if I understand you correctly): Approach #1 Let's check the size from the post_thumbnail_size filter. If it matches a corresponding size (e.g. full) then we make sure the $image_meta is empty, with the ...


4

The default post thumbnail/image sizes are set as follows thumb 150x150 medium 300x300 large 1024x1024 These defaults are set in wp-admin/includes/schema.php, currently in version 4.1 line 445 - 456 'thumbnail_size_w' => 150, 'thumbnail_size_h' => 150, 'thumbnail_crop' => 1, 'medium_size_w' => 300, 'medium_size_h' => 300, ..... ...


4

To add to the answer from @cristian.raiber, there is no function in Wordpress or php to detect screen sizes, and there will in all probabilty never be such functionality. Php runs server side, which runs before clients side which is browser side. As for php, and for that matter Wordpress, I cannot see any future implementation of any kind of function to ...


4

Sure - php can definitely handle simple math like this. All you'd have to do is reference the numbers coming back from the wp_get_attachment_image_src call: <?php if ( has_post_thumbnail()) { $full_image_info = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full'); $img_h = $full_image_info[1]; $img_w = $full_image_info[2]; ...


4

A workaround by extending the WP_Image_Editor_GD class The problem is how to access the image sizes before we change the quality of intermediate jpeg images. Note that the image_resize() function is deprecated. We can use the jpeg_quality filter from the public get_quality method of the abstract WP_Image_Editor class: $quality = apply_filters( ...


4

add_filter('intermediate_image_sizes_advanced', 'filter_image_sizes'); function filter_image_sizes( $sizes) { unset( $sizes['thumbnail']); unset( $sizes['medium']); unset( $sizes['large']); return $sizes; }


4

There is a way, I recommend you combine the imagefx plugin with a custom function , http://wordpress.org/extend/plugins/imagefx/ You can read about it here: http://ottopress.com/tag/gd/ , and use a function like one found here: http://stackoverflow.com/questions/1201798/use-php-to-convert-png-to-jpg-with-compression It would look something like (not ...


4

Re-size WordPress images on the fly using built-in WordPress functions. Use the vt_resize function to dynamically re-size WordPress images located in a custom field, featured image, uploads directory, NextGen Gallery WordPress plugin, or even an external link to an offsite image. It is very simple to use, just copy/paste the code below into your WordPress ...



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