i'm using joomla and want to restrict the user profile image size(dimension).
it is default to 10Mb but i want to restrict the image dimension something like 240x320 and below can be uploaded..
thanks..
You should hack into the joomla code for that particular upload thing and use
code like this for it:
list($width, $height) = getimagesize($image_file);
if ($width == 240 && $height == 320)
{
// nice proceed
}
else
{
// oops, invalid dimensions
}
I suspect you should place this code in controller of the plugin/component you are using the upload feature of.
I haven't used Joomla but you should see:
How to get image height and width using java?
If you are able to load the image into memory you could use Java's awt.Image class to get the width and height of the image and reject the image or scale the image to the desired size. Have a look at:
http://java.sun.com/j2se/1.5.0/docs/api/
I know that you can use JavaScript with Joomla so perhaps this would be worth a view:
link text - Uses javascript to get image dimensions.
I hope this is some help to you.
Related
I want to automatically add height and width attributes to all my images. It is perfectly done via this nice plugin, but I host my site on GitHub Pages where external plugins are not supported.
Question: How to prefill height/width attributes of an image without using a plugin?
Why do I need this?
My site works well even without height and width but I want to specify them because it is important from SEO point of view (you can find some details on its importance here).
Writing an internal filter to do this using the fastimage gem is fairly simple. You can define your filter in the _plugins directory of your project (this is outlined in the Jekyll documentation)
As a very rough example, you could do something like this:
require 'fastimage'
module ImageSizeFilter
def image_size(source, dimension = nil)
# Get the image dimensions, throw an error on failure
# NOTE: You may want to sanitize the input string provided here
# see: https://github.com/sdsykes/fastimage#security
size = FastImage.size(source, raise_on_failure: true)
# Return the requested dimension, or both dimensions if nothing was specified
return size[0] if dimension == 'w'
return size[1] if dimension == 'h'
return size unless dimension
# Fail if the requested dimension is invalid
raise 'Invalid image size dimension requested: ' + dimension
end
end
Liquid::Template.register_filter(ImageSizeFilter)
Which would be used like so:
<img src={{source}}
width="{{source | image_size: 'w'}}"
height="{{source | image_size: 'h'}}"/>
Of course this still won't work with GitHub pages directly because custom plugins are not supported. To use custom plugins in general, one solution is to build the site locally and include it in the repository.
This question seems to apply to content images in markdown files. These images have no width or height set by default.
The short answer
You can just set the width and height directly in HTML in your markdown, like this:
# Markdown title
paragraph
<img src="/path/to/image.jpg" width="400" height="300" />
The long answer
You cannot retreive the width and height of the image programmatically without a plugin, so when you use (pure) markdown you get an image without a width and height property. The question is WHY you wanted to add a width and a height in the first place. Setting the width and height prevents reflow, but it leaves a big gaping hole while loading. Is that truly better? It certainly does not look nice. Progressive JPG's are a very nice solution for this problem, but I do not prefer to set the width and height on them, as 'no image' looks good, and a progressive JPG also always looks good.
You say you want it for SEO reasons, but I cannot think of any.
If your website is so slow you actually want to interact with content below the image before the reflow, the logical solution is to make your website load faster.
However, if you have users with a really slow connection, you might want to manually add the image to the markdown in HTML. See the short answer for a code example.
Is there some easy way to scale an image to a maximum size?
Looking for some some easy way to keep file sizes down and scale images that are uploaded from the app to max 640 width for example.
I have googled several solutions, from module Ti.ImageFactory to just put it into an ImageView with a size, and get the blob back again (which should make it scaled?). The Ti.ImageFactory module seems very old though, several years ago updated if you look at GIT. Also the zip files for download seems to be missing on git...
Ex.
Titanium.Media.openPhotoGallery({
success:function(event)
{
Ti.API.info('Our type was: '+event.mediaType);
if(event.mediaType == Ti.Media.MEDIA_TYPE_PHOTO)
{
// HERE event.media needs to be scaled to a max
// size... for example 2 MB data, or max 960 px
// width/height or something similar
uploadPhoto(event.media);
}
},
cancel:function()
{
Ti.API.info("Photo gallery cancel...");
},
error:function(err)
{
//Ti.API.error(err);
Ti.API.info("Err: "+err);
alert(L("AN_ERROR_OCCURRED"));
},
mediaTypes:[Ti.Media.MEDIA_TYPE_PHOTO]
});
What you are looking for is the function imageAsCropped or imageAsResized.
Let me know if you need Further help.
You can use the size property.
size : Dimensionreadonly
The size of the view in system units.
Although property returns a Dimension dictionary, only the width and
height properties are valid. The position properties--x and y--are
always 0.
To find the position and size of the view, use the rect property
instead.
The correct values will only be available when layout is complete. To
determine when layout is complete, add a listener for the postlayout
event.
Documentation Link
I ended up using ti.imagefactory module.
The zip files for android and ios I found here:
https://github.com/appcelerator-modules/ti.imagefactory/releases
Example can be found here:
https://github.com/appcelerator-modules/ti.imagefactory/blob/stable/ios/example/app.js
I used code from the examples in my app and it seems to work fine!
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
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.
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/