Mediawiki Image Resizing - Trying to understand how it works - image

I have Mediawiki 1.21.2 installed. I have also set up ImageMagick on my server and have enabled it in LocalSettings.php. I have already read the Mediawiki's Images manual and I just need to clarify this:
If I am adding a plain image without adding the "thumb" option, will the image be automatically resized for the width I have mentioned or will it only skrink the dimension to that size but still has the original file size? For example, if I using this:
[[File:Sample_Image.jpg|250px]]
In the above statement, I can see that the image will be displayed with the maximum width of 250px. Lets say, if the original image is like 800px X 600px with a file size of 2MB, will the re-sized image for the above dimension will be reduced to only a few KB when the image is reduced to a width of 250px (or) will the image size shown in the article page will still have the original filesize of 2MB but only shrinked to 250px width but doesnt reduce the original filesize? I am just wondering since a lot of my users upload big pictures and these pictures have big file sizes. At the moment, I have added the image like this in my templates:
<div class="main_article_image">[[File:Sample_Image.jpg]]</div>
and then using css, I have minimized the image size like this:
.main_article_image {
max-width: 250px;
height: auto;
}
The current method resizes the images in the articles pages but the file size for these images are still huge and the article page takes too long to load. So I manually resize all images and upload a smaller size for images each time that takes more manual work. Therefore, I am trying to find out if adding the 250px with the image tag like: [[File:Sample_Image.jpg|250px]] will automate this work for me!
I have these settings on my LocalSettings.php for imagemagic:
$wgEnableUploads = true;
$wgGenerateThumbnailOnParse = true;
$wgUseImageMagick = true;
$wgImageMagickConvertCommand = "/usr/local/cpanel/3rdparty/bin/convert";
Can someone please confirm if this will work? Am I doing it the wrong way by resizing it via css? I know adding "thumb" parameter resizes the image, but will it work the same if for plain images without the thumb parameter? If it will, then I need to edit all of my templates and I just want to confirm before I go ahead changing the templates. Anyone who can clarify this will be helpful for me.

Yes, it seems that a smaller image file is generated even without the "thumb" parameter.
For example if you check the help page on images with the example "[[File:Example.jpg|50px]]" and check the url of the small image that is displayed, you'll see that it uses the thumb version /thumb/a/a9/Example.jpg/50px-Example.jpg instead of the full-size version /a/a9/Example.jpg

Related

How to keep aspect ratio for images added in jspdf

I want to generate pdf's with jspdf. These pdf's are a summary of an registration that users make in my app with an picture and some notes.
However when generating a pdf I need to supply the height and width of the image. first of I don't know this (though I can figure it out) second if the dimensions are bigger then my pdf they won't fit. And if i just make them smaller the aspect ratio will be ruined.
I am kinda looking for a solution much like in html where you use things like 'width: 70vw; height: auto;'
Any idea's on how to fix this?

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.

Is it better to use CSS / HTML to adjust an image size, or save multiple versions of the image?

Up until now, when a user has uploaded an image, I have been saving several different versions of it for use throughout my site. As the site has grown, so have the numbers of sizes needed.
At the moment each uploaded image is sized in to about 6 new images and saved on the server.
The downside is that every time I need to create a new size (right now, for instance, I'm making a new size for an image gallery), I have to cycle through all the thousands of images and re-cut a new size for each.
Whereas, when I started, it was a nice quick way to avoid resizing images on the fly, now it's starting to turn into a nightmare.
Is it better to continue saving different sizes, and just deal with the overhead, or is it better at this point to get maybe 3 general sizes, and resize them on the fly as needed?
"Resizing" images using html/css (e.g., specifying height & width) is generally not what you want to do - it results in poorly scaled images with artifacts from the resize, and is inefficient as the user is potentially downloading a much larger file than they actually need.
Rather, having some kind of server-side solution to allow for on-the-fly resizing is probably what you want. I'd recommend using ImageMagick - combined with the implementation for your favorite language and some web-server voodoo (e.g., using .htaccess for Apache), you can easily have /path/to/yourimage.png?50x50 fire a call to a resize script that resizes the image, saves it in a cache folder, and outputs the resized file to the browser. This is better all around - you get proper resizing, your user only downloads the exact file they need, and the end-result is cached so your resize action only occurs once. Check out Image::Magick::Thumbnail for an example (in perl)
Edit - if you respond to this with what server-side language/framework you are using, I would be happy to point you in the direction of a thumbnail/resizing implementation of ImageMagick or something else for your platform.
Multiple versions.
Some browsers simply don't scale these things well and you end up with choppy nasty in the image, bad pixelation, etc...
The exception could be if you know all the images are photographic. Then have versions for your larger sizes, but shrinking could be ok. But if these have illustration or text, the effect will be noticeable.
.resize {
width: 200px;
height : auto;
}
.resize {
width: auto;
height : 300px;
}

Resources