I am using html2canvas to save a webpage as png. Html2canvas is rendering/capturing svg's correctly in Opera and Chrome. However it is not rendering/capturing svg's completely on firefox. This is the code I am using. I am also using the latest html2canvas.
$(function() {
$("#btnSave").click(function() {
html2canvas($("#widget"), {
onrendered: function(canvas) {
/* theCanvas = canvas;
document.body.appendChild(canvas);
// Convert and download as image
Canvas2Image.saveAsPNG(canvas);
$("#img-out").append(canvas);
window.open(canvas);
*/
var a = document.createElement('a');
// toDataURL defaults to png, so we need to request a jpeg, then convert for file download.
document.body.appendChild(a);
a.href = canvas.toDataURL("image/png").replace("image/png", "image/octet-stream");
a.download = 'Human Insights - O&E.png';
a.click();
// Clean up
//document.body.removeChild(canvas);
// toDataURL defaults to png, so we need to request a jpeg, then convert for file download.
}
}, {
allowTaint: true,
});
});
});
This is the image captured using html2canvas on firefox version :56.0 running on windows 7
This is the image captured using html2canvas on chrome Version 61.0.3163.100 (Official Build) (64-bit) running on windows 7
Related
I am using gulp-webp to convert png images to webp format. Everything works smoothly and all images get converted depending on the quality settings I insert. Except the background. Images converted to webp always posses a black background. I tried playing with alphaQuality channel by setting the quality from 100 to a lower one. It does not show any changes.
Here is my gulpfile.js:
const gulp = require("gulp"),
imagemin = require("gulp-imagemin"),
webp = require("gulp-webp");
const { src, dest, watch, series, parallel, task } = require("gulp");
const themename = "portfolio",
Root = `../../${themename}`;
const sources = {
src: `${Root}/src/`,
scss: `${Root}/src/scss/`,
js: `${Root}/src/js/`,
img: `${Root}/src/img/`,
webfonts: `${Root}/src/webfonts/`
};
const distribution = {
dist: `${Root}/dist/`,
css: `${Root}/dist/css/`,
js: `${Root}/dist/js/`,
img: `${Root}/dist/img/`,
webfonts: `${Root}/dist/webfonts/`
};
const webpConvert = () => {
return src(`${sources.img}**`)
.pipe(webp({}))
.pipe(dest(distribution.img));
}
task("webpConvert", webpConvert);
I would appreciate any kind of advice how to convert webp with transparent background.
I am answering my own question. Maybe I will save someone from confusion I had. As you can see in the code above I instructed webpConvert function to convert all the files in the img folder to webp:
const webpConvert = () => {
return src(`${sources.img}**`)
.pipe(webp({}))
.pipe(dest(distribution.img));
}
The catch was that I already had some webp images that I converted manually earlier in my scr/img folder. So gulp-webp plugin took those webp images and double-made them into webp. This had obscured the alpha channel. Make sure, you don't have any webp images in your source folder if you are using this plugin or at least instruct the function not to convert them again.
I converted all my images to WebP using gulp-webpand I'm using Modernizr to check if webp is enabled and if so, create a new img tag with the webp url. It's working as intended on desktop as far as I can see on Google Page Speed, but on mobile, it says Serve images in next-gen formats still.
Is there another step you have to take for it to work on mobile devices? I can't find anything about it anywhere and I've set up webp exactly as Modernizr says.
Any help would be appreciated.
Modernizr.on('webp', function (result) {
$('.noscript').each(function() {
let img = document.createElement('img');
img.alt = this.getAttribute('data-alt');
img.className = this.getAttribute('data-class');
if (result) {
img.src = this.getAttribute('data-webp');
} else {
img.src = this.getAttribute('data-original');
}
this.parentNode.insertBefore(img, this.nextSibling);
});
});
Then I'd do this in the HTML:
<noscript data-alt="Payment Logos" data-original="/images/common/payment-foot.png" data-webp="/dist/images/common/payment-foot.webp" data-class="mobileHide lazyload" class="noscript">
<img src="/images/common/payment-foot.png" alt="" class="mobileHide">
</noscript>
I am using CKFinder 3 intergrated with CKEditor. Now, after resizing an Image and clicking on Choose Resized, I want to move/copy the resized image to another folder using javascript. I am able to get upto the following code.
CKFinder.start({
onInit: function (finder) {
finder.on('file:choose:resizedImage', function (event) {
var file = event.data.file;
var resizedData = file.get('imageResizeData');
var resized = file.get('imageResizeData').get('resized');
// Need help here to move the resized image to another folder.
});
}
});
NOTE: I am using ASP.NET Connector.
You can use command:send request to send CopyFiles request:
https://docs-old.ckeditor.com/ckfinder3/#!/api/CKFinder.Application-request-command_send
Parameters taken by CopyFiles can be found here:
https://docs-old.ckeditor.com/ckfinder3-net/commands.html#command_copyfiles
We have implemented FineUploader and are running into an issue with some images that our clients are uploading. For large image files with a repeated canvas texture, FineUploader resizes the images fine, but a moiré is introduced into the final image. Is there any way to help prevent this from happening?
Here is an example:
http://205.238.27.187/Hagan/site/Artwork-Detail.cfm?ArtistsID=1110&NewID=10709
This is not because of the quality setting.
Most browsers use linear interpolation rather than bicubic when resizing images.
Fine Uploader uses the default browser image resizing algorithm.
The solution I've found is limby-resize. It uses pixel averaging/a much better resizing algo but is more CPU intensive. There is a link to a demo in the readme file. (Fine Uploader uses the "Crappy" method)
In megapix-image.js around line #168 or in the fine uploader source code,
Replace:
else {
ctx.drawImage(img, 0, 0, width, height);
}
canvas.qqImageRendered && canvas.qqImageRendered();
With:
else {
var tmpCanvas = document.createElement("canvas");
tmpCanvas.width = iw;
tmpCanvas.height = ih;
var tmpCtx = tmpCanvas.getContext("2d");
tmpCtx.drawImage(img, 0, 0);
canvasResize(tmpCanvas, canvas, function () {
alert("Image resized by limby-resize");
canvas.qqImageRendered && canvas.qqImageRendered();
});
}
And include limby-resize's canvas_resize.js before the fine uploader js file in your HTML.
Using AngularJS:
I'm displaying a list of images with ng-repeat. When I reset and rebuild the model (get new data from backend), I'm displaying the same images as before.
I understand these are new elements created by ng-repeat, but the image srcs are the same. Unlike IE or firefox, Chrome tries and gets a 403 for those same images and then renders them.
That causes a flicker. On IE and Firefox the images come from cache. No hit on the server to check for image changes. No flicker.
How can I prevent that? Should the images be served with some cache header? I tried loading the images to a dataurl, but then I hit the CORS problem, and would have to proxy those images on the backend to get them.
Possibly related: Chrome sometimes reloads image after jQuery .appendTo, recieves 304
Thanks
Some fix would be related to preload the images in javascript and after that display them
function loadImages(arrayOfImgs) {
var imageNumber=0;
$(arrayOfImgs).each(function(){
(new Image()).src = this;
if(arrayOfImgs.length == imageNumber) $scope.showImages = true;
else imageNumber++;
});
}
// Usage:
loadImages([
'img1.jpg',
'img2.jpg'
]);
if you are retriving images from backend use it at success promise
i hope it helps you
Check that example retrinving images from backend:
$scope.loading = true;
getImages().then(function (response) {
var objects= response.results;
var listImages = [];
angular.forEach(objects, function (item) {
listImages.push(item.UrlImage);
});
function preload(arrayOfImages) {
var numImages = 0;
$(arrayOfImages).each(function () {
var img = (new Image());
img.src = this;
$(img).load(function () {
numImages++;
if (numImages == arrayOfImages.length){
$scope.loading = false;
}
});
});
}
preload(listImages);
});