Tag Info

Hot answers tagged

11

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


11

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


11

When an image is uploaded in WordPress, it is saved in its original size, and also in some resized copies in different sizes, in this way became easy use different size of the same image for different purposes. By default, WordPress, create 3 copies in 3 different size: 'thumb' 'medium' 'large' The size in pixel for these 3 sizes can be setted in ...


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


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

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


8

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


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

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


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


6

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


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

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


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

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

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

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


4

I decided to use this, which is based on @AndresYanez's answer: function get_image_id_by_link($link) { global $wpdb; $link = preg_replace('/-\d+x\d+(?=\.(jpg|jpeg|png|gif)$)/i', '', $link); return $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE BINARY guid='$link'"); } This is much more succinct (since it doesn't jump through the ...


4

Misspelling of thumbnail (thumnail) in the if statement. Also get_the_post_thumbnail does echo the thumbnail, but just returns the html. You need to echo it. Also, for checking if a post has a thumbnail, you can use has_post_thumbnail. if ( has_post_thumbnail($r->ID)) { echo get_the_post_thumbnail($r->ID, array(50,50)); }else{ echo ...


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

WordPress automatically resizes uploads into different formats based on the settings on the Settings » Media page: You can set up all of your different default sizes here. Though keep in mind that plug-ins and themes can define their own custom image sizes ... so I can't guarantee perfect operability in all cases.


4

I am assuming that WP takes the additional parameters at the end of the file name to automatically resize the image... Wordpress adds those suffixes when it creates the images, which is typically done on image upload. Those images should be on the server. By default (and if I am not mistaken), WordPress does not do any dynamic image resizing on page ...


4

You can call add_image_size in your functions.php: add_image_size( 'medium', 240, 160, true ); Reference here: http://codex.wordpress.org/Function_Reference/add_image_size


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

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

This sounds like a description of the JetPack's Photon service. Photon is an image acceleration and modification service for Jetpack-connected WordPress sites. Converted images are cached automatically and served from the WordPress.com CDN. Images can be cropped, resized, and filtered by using a simple API controlled by GET query arguments. When ...


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


3

There is a filter to use for the array containing the filename that is saved to postmeta but since there are no filters available to change the filename before it is saved you have to manually change it using rename(). function wpse_filter_image_resize_name( $filename ) { $new_name = preg_replace( "/-(?<match>\\d)/ui", "_$1", $filename ); if ...


3

WordPress shows whichever image is requested by the function that outputs those images in the template. The presentation of images is entirely up to the theme developer, WordPress doesn't make this decision on its own. For example, the_post_thumbnail function: the_post_thumbnail('thumbnail'); // Thumbnail (default 150px x 150px max) ...



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