How do I resize/access original images in wordpress? - image

Where do the images resize in wordpress? In a database? In a folder?
How would I go about resizing the original image (not create a new version). I ask this, because I uploaded quite a few images that are too large and slow down load times on a wordpress site, and I want to resize them so there aren't any dimensions larger than 1500px.
I've already looked at a few plugins, including "regenerate thumbnails", but there may be one that actually does what I want that I haven't been able to find yet.

Well, the images resize "on the fly", then stored in the server and its information recorded in the database.
The original remains and all "thumbnails" are generated. In this case, "thumbnails" refers to all WP generated image sizes, big or small.
I answered the same question at WordPress StackExchange. And the solution comes from this article: How to automatically use resized images instead of originals.
This script will replace the uploaded image (if bigger than the larger size defined in your settings) by the large image generated by WordPress to save space in your server, and save bandwidth if you link a thumbnail to the original image, like when a lightbox plugin is used.
add_filter('wp_generate_attachment_metadata','replace_uploaded_image');
function replace_uploaded_image($image_data)
{
// if there is no large image : return
if ( !isset($image_data['sizes']['large']) )
return $image_data;
// paths to the uploaded image and the large image
$upload_dir = wp_upload_dir();
$uploaded_image_location = $upload_dir['basedir'] . '/' . $image_data['file'];
$large_image_location = $upload_dir['path'] . '/' . $image_data['sizes']['large']['file'];
// delete the uploaded image
unlink($uploaded_image_location);
// rename the large image
rename($large_image_location, $uploaded_image_location);
// update image metadata and return them
$image_data['width'] = $image_data['sizes']['large']['width'];
$image_data['height'] = $image_data['sizes']['large']['height'];
unset($image_data['sizes']['large']);
return $image_data;
}

You can use WordPress' add_theme_support and add_image_size to add multiple sizes for an image, which means that WordPress will create a copy of the post thumbnail with the specified dimensions when you upload a new thumbnail. To learn more about these technics you can read this tutorial.
There is also another function in WordPress and it's image_resize that can be used to scale down an image to fit a particular size and save a new copy of the image.
Most developers uses add_image_size to add multiple image size to show in different palces, i.e. you can use one image as a featured image in your home page and also can use another size of same image in the single.php page. To do this you have to use
add_theme_support( 'post-thumbnails' );
add_image_size( 'homepage-thumb', 220, 180 ); // 220 pix width,180 pix height
add_image_size( 'singlepost-thumb', 590, 9999 ); // Unlimited Height Mode
To show the homepage-thumb image in your home page you can use
if ( has_post_thumbnail() ) { the_post_thumbnail( 'homepage-thumb' ); }
Or in the single.php template you can use
if ( has_post_thumbnail() ) { the_post_thumbnail( 'singlepost-thumb' ); }
Also you can take a look at this plugin and this article could be useful too. Hope it helps.

To my knowledge there is no plugin that will directly resize your original images and change their meta data, but I've found a workaround (I had a similar problem to yours) which does not require coding.
Download your images by FTP (images are stored within the wp-content/uploads/ directory)
Make your resize/editing operations with the software of your choice and re-upload your images using FTP exactly to the same place they were before (you should not change anything in the folder structure or filenames)
Install WPR Rebuild Meta Data plugin in your Wordpress Admin. Go to "Tools -> Rebuild Meta". This will rebuild all the modified image meta data (for example it will update the new image sizes into the database)
Install Force Regenerate Thumbnails plugin in your Wordpress Admin. You can use it from "Tools -> Force Regenerate Thumbnails" to do it for all your images, or from the Wordpress Media Manager to do it just for the images you've changed. This will delete the old thumbnails and custom image sizes, and create fresh ones from your new images.

Related

Possible to get varying sizes of Tumblr theme options uploaded images?

In using Tumblr theme tags, you can use {PortraitURL-16} or {PortraitURL-128} to get a 16x16px or 128x128px (respectively) portrait image URL. Similarly you can use {PhotoURL-500} to get a 500px wide URL to that image in a photo post.
I'm wondering if it is at all possible to do the same thing (specify a dimension value) for custom uploaded images in my Tumblr theme. For example, I use {image:Avatar}, and if someone were to upload a 1280 pixel-wide photo, I'm still going to be display it at 60x60px. Is there any way to specify {image:Avatar-60} so I'm not loading a huge image on every page load?
Afaik, no. Images are processed in three different ways on Tumblr.
Photo / Photoset / Panoramic Post
When creating a new Photo / Photoset post any images added, Tumblr will process, and create multiple copies at various sizes. You can then retrieve a specific size by using the appropriate theme operators:
{PhotoURL-HighRes}
{PhotoURL-500}
{PhotoURL-400}
{PhotoURL-250}
{PhotoURL-100}
{PhotoURL-75sq}
Theme Assets
You can also upload an image whilst customising a theme, via the customisation page. Unlike Photo / Photoset Post, these images are processed and retain their original size and multiple sized versions aren't created.
Post Body / Caption
Finally you can upload an image whilst adding content to the post body / caption. These images are processed and capped at 500px high / wide.
Hope that helps!

WordPress / WooCommerce upload media creates 19 additional image sizes

I'm using WooCommerce for a client website, and I'm having an issue with disk space. When an image is uploaded for a product, the system seems to be creating 19 other image sizes for the original image.
Now I know that I set a Thumnbail, Medium, Large and so on in the Media Settings and in WooCommerce settings, but I don't understand why it's creating 19 other sizes?
Here's a screenshot of an image in my wp-uploads/2014/01 folder:
As you can see, one image will take up a fair amount of space - I've got to consider that each product has at least 4 different images!
How do I reduce the amount of images that are being created?
This is because a certain plugin or current theme is registering image sizes. Each registered image size generate an image of that particular dimensions. You need to find out which plugin or theme is doing so. Normally, that should be your theme. Look in your theme's function.php or plugin files and find function calls like this:-
add_image_size( 'category-thumb', 300, 9999 );
Remove the required add_image_size function calls to avoid generating multiple copies of the image.
http://codex.wordpress.org/Function_Reference/add_image_size

Wordpress upload image size

Kinda new to wordpress.. Creating my own theme. When I upload an image and put it in a post it comes out at 300x183 pixels but the original file I upload is 1800x1100 pixels. Wordpress alters my size when i upload it.This is what i get in the url on the post NDAppleProductMockUp-300x183.jpg.. It restricts the size of the image. When i go into the image properties within the post and click original nothing happens it stays at 300x183.. I have tried to work it out but can't Any suggestions guys..
Thanks
Unfortunately, WordPress does not resize the actual image that you upload. It creates 3 smaller versions of it, leaving the uploaded image untouched. I would suggest that you create all of your images at 1800x1100 before you upload them.
Another solution would be to link to the "big-sized" image when you "Insert into Post"... unfortunately, you would have to know the filename of the large image. I check the source code and this part of the media system does not appear to be pluggable.
Another option may be to check out this plugin:
http://wordpress.org/extend/plugins/nextgen-gallery/
This link here details how You can change what image size will be displayed
http://codex.wordpress.org/Function_Reference/add_image_size
also when u attach to post you can set the image size in the setting
THE SETTING is Before you attach the image!
you are trying to change an image that has already been attached (the attached image was in a mid or small size to begin with) so it is already at its original size.

Image reduce website content

My site have 2 pages and the 2 pages contain a similar picture. If a user comes to the first page, he downloads the picture and then come to the second page, if I make the website so that the picture is shared between the 2 pages then the user no need to download the picture again?
If I want to put the same picture but different in size on the webpage, is it better to make 2 pictures by using image software editor or using CSS to change the width and the height of the picture?
you have answered your question.
if the image is from the same source, and if you have configured the caching on webserver correctly (and if the client has enabled cache), then there are no re-requests sent to view the same resource.
you dont need to create multiple images for different sizes, use html image attributes to show it in the grid dimensions you wish to.
Exception: if the original image is quite large, and you are not sure if the user will want to view the image, then create smaller image for faster loading. Thumbnails on a photo album is a good example for that. There is a program called re-sizer which accepts a folder and create a new set of images with the required dimensions
Resources below
Image Resizer
HTTP Compression

Why does the add_image_size() function not create a copy of the thumbnail image in wordpress?

I have uploaded a photo in WordPress. I am trying to post a thumbnail of the image using a predetermined width while constraining the height proportionally.
In functions.js:
add_image_size('width-130', 130, 0, false);
On the page that outputs the thumbnail:
the_post_thumbnail('width-130');
According to the WordPress docs(http://codex.wordpress.org/Function_Reference/add_image_size), it says:
WordPress will create a copy of the post thumbnail with the specified
dimensions when you upload a new thumbnail.
Currently it is outputting the full thumbnail image with a width attribute of 130. This still requires the full size image to load, which is not what I want. I would like for WordPress to create an actual copy of the post thumbnail with the correct dimensions, and not just to set the width attribute. How can I achieve this?
I discovered my mistake.
Since I had not re-uploaded the image file, it was still trying to access the full size image which was the assigned image for that post, while adding the width attribute. Once I re-uploaded the image, the add_image_size() function is now actually creating a copy of the thumbnail with the correct dimensions.
I apologize for asking this question. If the community wants, I can close it but I figure it might be good reference for WordPress newbies such as myself.
Use this plugin to regenerate thumbnails.
http://wordpress.org/plugins/regenerate-thumbnails/
In case anyone runs across a similar problem, this may help. add_image_size generates derivatives that are smaller, but not bigger or the same size. Thus if you are trying to make a monochrome derivative image, uploading an image the same size as the monochrome, it will not be available and techniques like this one won't work.

Resources