Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange
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 ) ...


14

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


14

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


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


10

Add this to the functions.php file in the theme folder. It replaces the original image with the large image set in settings. You might want to setup a new image format and use that as the new original size though. function replace_uploaded_image($image_data) { // if there is no large image : return if (!isset($image_data['sizes']['large'])) return $...


9

You can also filter intermediate_image_sizes with an empty array. add_filter( 'intermediate_image_sizes', '__return_empty_array' );


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


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


7

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


7

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


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


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

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/ https://stackoverflow.com/questions/6382448/png-transparency-resize-with-simpleimage-php-class


6

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


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

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


6

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


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

image_make_intermediate_size was not the hook I was looking for, but intermediate_image_sizes_advanced. Here is a working code: function disable_upload_sizes( $sizes, $metadata ) { // Get filetype data. $filetype = wp_check_filetype($metadata['file']); // Check if is gif. if($filetype['type'] == 'image/gif') { // Unset sizes if ...


4

Custom Image Sizes Resizing without cropping is already part of the core functionality, via add_image_size(). Note the last parameter: <?php add_image_size( $name, $width, $height, $crop ); ?> The Codex entry describes the $crop parameter as follows: $crop (boolean) (optional) Crop the image or not. False - Soft proportional crop mode ; ...


4

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


4

You can get the original sizes of the image being uploaded: list( $uploaded_width, $uploaded_height ) = getimagesize( $_FILES['u_img']['tmp_name'] ); Then you can use those values to size the image as you like: $height = 300; $image = wp_get_image_editor( $_FILES['u_img']['tmp_name'] ); $image->resize( $uploaded_width, $height, true );


4

This is another approach than the other answer that works when importing content with the importer and fixes the URLs once and for all. Again: This is not battle-tested but is the solution I settled on and it did work. I prefer this as it solves the issue once and for all and if it works, it works. As you are not leaving broken stuff in the DB and fix it on ...


4

You could e.g. check the filename and extension from the pathinfo, after your custom sanitization. Example: If the filename is empty and extension non-empty, then add the formatted current time as the filename part: $info = pathinfo( $file['name'] ); if( empty( $info['filename'] ) && ! empty( $info['extension'] ) ) $file['name'] = sprintf( '%s....


4

Use the jpeg_quality and wp_editor_set_quality filters to set the quality of resized images: add_filter( 'wp_editor_set_quality', 'wpse246186_image_quality' ); add_filter( 'jpeg_quality', 'wpse246186_image_quality' ); function wpse246186_image_quality( $quality ) { return 100; // 0 - 100% quality } I have not been able to reproduce the issue reported; ...


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 class="meta-nav"...


3

You can use image_downsize filter and to catch when WordPress wants a downscaled image and not original, and actually a size what doesn't exist. add_filter( 'image_downsize', 'wpse_60890_retina_scale', 10, 3 ); function wpse_60890_retina_scale( $value, $id, $size ) { if ( $size == 'wpse_60890_retina_scaled' ) { if ( !is_array( $imagedata = ...


3

There's one nasty bug in the solution above. The solution works as a charm for new images, but for old images, you should never compare to $upload_dir['path'] because that's the current upload folder of the current month. Replace the following: //$large_image_location = $upload_dir['path'] . '/'.$image_data['sizes']['large']['file']; $large_image_location =...


3

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


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