How to auto generate custom image sizes - image

I got strange behaviour when I added filter for attachment_fields_to_save, when I save the images, it does not want to save image metadata such as title, description and caption.
Why I need to add this filter? Because I have lots of custom sizes using this code:
add_image_size("imagesize-940x360", 940, 360, true);
And the image may not correctly put in good place, so the user need to use Wordpress awesome tools to edit the image like cropping and scaling.
For some silly reason (or perhaps this is bug), the Wordpress does not generate image for custom image sizes.
In order to achieve generation for custom sizes, I need to add filter when user press save button in the Wordpress image editor. Here is the piece code that I been using:
add_filter("attachment_fields_to_save", "rl_regenerate_image", 99, 2);
function rl_regenerate_image($post, $attachment)
{
$id = $post['ID'];
$fullsizepath = get_attached_file($id);
wp_update_attachment_metadata($id, wp_generate_attachment_metadata($id, $fullsizepath));
return true;
}
The code above generates the custom sizes when user edit the image correctly but sadly it does not save all updated metadata images such as title, caption and description.
Do you guys know how to solve this problem? So what I would like to achieve is how to generate "edited" images for custom sizes and save the metadata correctly.
Thanks in advance!

In case this hasn't been solved yet, or for any Googler's out there.. Here's a plugin called Post Thumbnail Editor that lets you edit individual custom image sizes. Works well.
http://wordpress.org/extend/plugins/post-thumbnail-editor/

Related

Is it possible to position image title/caption above the image in Asciidoctor

Currently, all image caption I have used are automatically placed before an image, despite me placing the caption before the image in the code.
For example,
[caption=]
.Simple diagram of data storage
image::user-guide/data-storage.png[width="600"]
Is there any way I can re-position the caption such that it appears above/before the image like how table titles are positioned above a table?
I assume you're using the standard HTML5 output of Asciidoctor. This can't be parameterized; the HTML will always render first the image and then the title element.
You could override the rendering of images in the HTML5 backend, or create your own backend to structure the output as you need.
In addition to #ahus1's answer, you might be able to achieve the presentation you desire by applying a custom stylesheet via docinfo files. See https://asciidoctor.org/docs/user-manual/#docinfo-file

Check if an image contains another image

Im trying to check if a screenshot contains an image that is saved in the project resources, I need to find a 100% match only and would like to not use any extra libraries, now with that being said, I have no idea how to do so.
heres a few questions:,
do I compare the two buffered images together? do I change them into something else?
Il have to compare it atleast once a second or so. (just as general information)
I have a resource folder under my project in eclipse and the .png files are shown as text, is there a way to change that? I tried tinkering with the settings, no luck yet.
public static BufferedImage screenshot(){
BufferedImage capture = robot.createScreenCapture(screenSize);
return capture;
}
this is my screenshot, another bufferedimage is for example "compare", where the size of the compared image is smaller than the screenshot. how will I be able to check if the image contain the second image?
*For those who wondering, im trying to make a simple program that clicks a certain image once it pops up.

Drupal resize image on the fly

Is it possible to resize images on the fly and cache the result with Drupal?
I have some big images (e.g. 2000x2000px) and I want to display a preview of the e.g. 100x100px.
I know there is a theme_image_style function. But it seams to only create the <img> with the right size and not effectively resize the image.
I look at modules/images/image.admin.inc and they used the function [image_style_create_derivative][2].
Yes, you should use Drupal's Image styles (Configuration -> Media -> Image styles). There you should create your style.
Then, on front-end, when ever you want to display image with that style (in that resolution) you can use image_style_url() function:
https://api.drupal.org/api/drupal/modules!image!image.module/function/image_style_url/7
It accepts 2 parameters - one is image style machine name and other is image URI, which you can get if you print out all image field properties.
You can also select image styles from back-end interface...i.e. when creating a view for some image you can select to be displayed in specific image style.
In both cases those image styles are generated the first time image is used.
In response to your comment on MilanG's answer, using image_style_url() is the best option on the backend. There is also
https://www.drupal.org/project/resp_img
which may be something worth looking into. From a UX perspective, you don't want to force the user to load a 2000x2000 px image every time they load the page. Regardless of the outputted size, the image is still going to render as a 2000x2000 px image with a large size. image_style_url() or using image styles in the GUI create a new file that will load much quicker and is the preferred method.

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.

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