Tag Info

Hot answers tagged

13

The only time setting the quality really matters is right before the image is saved or streamed (for the editor). Both of these have the "image_editor_save_pre" filter there, passing it the instance of the image editor. So you can use that to modify the image in any way you like, including setting the quality. So, something like this should do the job ...


9

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


6

No, it won't create a new image that is exactly the same size.. nor should it. All the thumbnail, medium, and large images are resized images, by definition. Since the original image is already 600x600, there's no point in creating another file at the same size, but with a lower quality (remember that JPEG compression is lossy). However, if you specify in ...


5

Note upfront: Below answer isn't finished and is not tested, but I ain´t got enough time left, so I'll leave this here as draft. What probably needs a second pair of eyes is the quality method and the interpretation of version_compare(). First we need an entry point. After reading through the make post again, I thought best would be to jump in before the ...


5

To built on Max Yudin's answer you should use the intermediate_image_sizes_advanced filter, and not image_size_names_choose. function add_image_insert_override($sizes){ unset( $sizes['thumbnail']); unset( $sizes['medium']); unset( $sizes['large']); } add_filter('intermediate_image_sizes_advanced', 'add_image_insert_override' ); Another easier ...


5

Basically you just retrieve the info via getimagesize(), a basic PHP function, a then handle your errors with notes. The plugin A basic plugin as a starting point: <?php /** Plugin Name: (#67107) »kaiser« Restrict file upload via image dimensions */ function wpse67107_restrict_upload( $file ) { $file_data = getimagesize( $file ); // Handle ...


4

You can perform a combination of things to accomplish a smaller file size. Let me guide you through it. Firstly, you could add custom image sizes and adjust the dimensions to the very smallest for their purpose. Put the following in your functions file: function my_insert_custom_image_sizes( $sizes ) { // get the custom image sizes global ...


4

Figured it out after a lot of trial and error and a lot of var_dumps. $image = wp_get_image_editor($file); if ( ! is_wp_error( $image ) ) { $image->resize( $width, $height, true ); $final_image = $image->save( $file ); } Then i can use the $final_image array to get what i need. It actually saved me a step from what i was doing and seems ...


4

I'd try saving it as a PNG 24 first. If that doesn't work have a look at these: http://www.akemapa.com/2008/07/10/php-gd-resize-transparent-image-png-gif/ http://stackoverflow.com/questions/6382448/png-transparency-resize-with-simpleimage-php-class


4

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


4

i guess you are looking for this add_attachment and delete_attachment example: add_action('add_attachment', 'attachment_manipulation'); function attachment_manipulation($id) { if(wp_attachment_is_image($id)){ //do your own tasks } }


3

There's a lot going on here. First off, you should store the repeater field image as an ID (that probably requires changing how the subfield's setting and possibly re-uploading some of your images) and then use all the WordPress Core API functions to handle it. (You'll probably cross paths with wp_get_attachment_image_src.) That gets rid of your regex-ing, ...


3

WordPress and TimThumb both use GD to resize images, so quality is going to be similar. GD's resize quality is not as good as Photoshop, you'll notice this especially in fine details. Both WP and TimThumb can be modified to use ImageMagick, WP via a plugin, TimThumb I think requires you edit the code directly, which is not ideal. ImageMagick will give ...


3

Adding a post thumbnail is pretty easy, open content.php, if you're using excerpts on your homepage find this <?php the_excerpt(); ?> then add this just above that line <?php the_post_thumbnail('thumbnail', 'class=alignleft'); ?> If you're not using excerpts add it above <?php the_content( __( 'Continue reading <span ...


3

If I remember right you have to unset all the defaults and add the new Size there: <?php function mxdCustomImageSizes($sizes) { unset( $sizes['thumbnail']); unset( $sizes['medium']); unset( $sizes['large']); unset( $sizes['full'] ); $myimgsizes = array( 'full-size' => __( 'Full Size' ) ); if( !empty($sizes) ) ...


3

In this case I would add image size in functions.php which registers new image size in my theme and get the re-sized image. Example: Register custom image size (functions.php) if ( function_exists( 'add_image_size' ) ) { add_image_size( 'custom-image', 440, 265, true ); //(cropped) } Get custom image size (functions.php) function ...


3

use add_image_size() to define you custom image size 1.register custom image size (functions.php) if ( function_exists( 'add_image_size' ) ) { add_image_size( 'custom-image', 440, 265, true ); //(hard cropped) } 2.get image in custom image size except featured image of post (functions.php) function ravs_get_custom_image( $featured_img ){ global ...


3

I believe your issue is that the value set for the global $content_width variable (which is 640px in Boilerplate and 584px in Twenty Eleven) is less than the width you're specifying via Settings -> Media. WordPress is overriding your user setting with the Theme-specific value. This actually makes sense, since a Theme knows its maximum content width, and ...


3

WordPress by default is designed to generate 3 types of cropping of any uploaded images (Media): Thumbnail (Typically 150px x 150px) Medium (Typically 300px x 300px) Large (Typically 1024px x 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 ...


3

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


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


2

Users shouldn't have to know anything about image sizes. Just have them upload as-large-as-needed images and your job is to get WordPress to do the rest. When a user uploads an image, WordPress will generate as many images as you've declared with add_image_size(). An example from the codex for your functions.php file: if ( function_exists( ...


2

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


2

Since you know the location of the image on the disk you can use wp_insert_attachment to insert your big image to the media library. By default this will generate also several smaller versions of the big image that you might not need but this is the easiest way to make all the media related plugins to be aware to your image.


2

Download the script (or add it via npm > bower to your theme), wp_enqueue_script() it at the wp_enqueue_scripts hook and then simply add/enqueue another (your custom) script where you add the contents of the demo index.html file: ( function( $ ) { $( "img" ).photoResize( { bottomSpacing: 15 } ); } )( jQuery || {} );


2

First of all pay attention that image_resize() function is deprecated! Use wp_get_image_editor() instead of it. This function will return an instance of WP_Image_Editor class (or WP_Error if some issues appear during loading your image). This class has resize method which accepts three arguments: desired width, desired height and crop flag. Sample usage: ...


2

WordPress doesn't regenerate the newly registered size, only applies it to future uploads. You'll have to use something like the Regenerate Thumbnails plugin or one of the similar ones available at WordPress.org.


2

Here's my take on it <?php /** * Plugin Name: Deny Giant Image Uploads * Description: Prevents Uploads of images greater than 3.2MP */ function tomjn_deny_giant_images($file){ $type = explode('/',$file['type']); if($type[0] == 'image'){ list( $width, $height, $imagetype, $hwstring, $mime, $rgb_r_cmyk, $bit ) = getimagesize( ...


2

Try seperating it like this: function setup_image_sizes() { if ( function_exists( 'add_image_size' ) ) { add_image_size( 'post-image', 608, 350, true ); } } add_action( 'after_setup_theme', 'setup_image_sizes' ); function post_image_sizes($sizes){ $custom_sizes = array( 'post-image' => ...


2

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



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