How to keep aspect ratio for images added in jspdf - image

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?

Related

Keep bots and crawlers from recognizing images

I want to present an image to my visitors, and I don't mind if they download it (they can always take a screenshot anyway), but I don't want this image to appear in any search results ever.
While I know that I can politely ask bots not to index my content, I don't trust them. Therefore, I want them to not recognize my image. Two ideas:
Create my image through e.g. PHP's image functions: <img src="image.php">. But I guess Google understands this.
Publish my image as a table, with each cell 1x1 pixels and the background color of that pixel: <td style="width:1px;height:1px;background-color:#36ef2a"></td>.
Better ideas?
Does this include not trusting /robots.txt file in your setup? Not sure if that is what you meant.
What type of images are they? If they are mostly text, and can be represented with drawings, you can try using the HTML5 Canvas Element and/or Inline SVG to present your image.
I'm not sure if you can use background images to help your point inside the CSS.

Mediawiki Image Resizing - Trying to understand how it works

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

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

crystal reports image squashed

Is there any way in Crystal Reports(v11, if this matters) to prevent the images from stretching itself to fit in the whole OLE-object? I'm loading the images dynamically from a database and don't know their aspect ratio.
Thanks for help.
i found the answer here
To make the image resize properly, you must perform the following steps in order:
Set the image's EnableCanGrow to true
Calculate and set Width and Height to the needed size
Set the image's EnableCanGrow to false
Fill the DataSet's image object with data
Continue with normal report processing.
If you get these items in the wrong order, or skip an item, you will
find that Crystal Reports scales the image in unexpected and unrecoverable ways.
The Crystal OLE object, which shows pictures from files, can only be set programmatically so for a 'pull' type report, where you are supplying a dynamic image name, of either portrait or landscape orientation, at least one of those orientations will get squashed to fit. It is better, IMHO, to show thumbnails and then have a calculated hyperlink to show the real picture in some decent viewer. You will spend an unreasonable amount of time trying to get the OLE object that shows pictures to understand that your image has a different aspect ratio. As long as it is at least reasonably legible that may have to suffice.
I don't think Crystal can help you. Try looking for some kind of command-line based app on the internet which can automically resize pictures (add black space, reduce in a 1:1 ratio, etc). I'm sure they're out there.

Resources