Chrome crops image in famo.us - google-chrome

I have a background (svg) image that I initially will view zoomed in and then on an event the image will zoom out to fit in the page. This works well in Firefox but in Chrome the picture was cropped when zoomed in and thus when it is supposed to fit the page it has white space around it. I believe this is part of Chrome's optimizer described here: http://famo.us/guides/pitfalls
My question is then, can I disable this optimization for this specific image? Or is there any other solution?
Edit: No need to look at the Chrome optimizer, solved by using better method for zooming (from correct answer below).

Athough we do not know your use case, here is an example using proportions.
Example jsBin (click on the image to resize)
var mainContext = Engine.createContext();
mainContext.setPerspective(1000);
var mod = new StateModifier();
var logo = new ImageSurface({
content: 'http://code.famo.us/assets/famous_logo.svg',
classes: ['double-sided']
});
logo._mod = new Modifier({
size: [undefined, undefined],
origin: [0.5, 0.5],
align: [0.5, 0.5],
transform: Transform.translate(0, 0, 0),
proportions: [1.5, 1.5]
});
var mainMod = new Modifier({
origin: [0.5, 0.5],
align: [0.5, 0.5]
});
var rootnode = mainContext.add(mainMod);
rootnode.add(logo._mod).add(logo);
//logo._mod.setProportions([1.5, 1.5], {duration: 2000});
logo.on('click', function(){
if (!logo.small)
logo._mod.setProportions([1,1], {duration: 1000});
else
logo._mod.setProportions([1.5, 1.5], {duration: 1000});
logo.small = !logo.small;
});

Related

html2canvas not rendering properly (overlapping color)

I am using html2canvas and jsDoc. I am rendering my current component html to pdf.
But somehow color of other component is overlapping to the current component after I download the pdf. This is Angular component.
Screenshots :
Screenshot from application
Screenshot from pdf viewer (Sidebar visible):
3.Screenshot from pdf viewer (Sidebar hidden):
You can see the color is overlapping from submit button till end.
Code :
downloadPdf() {
html2canvas(document.querySelector(".main-content")).then(canvas => {
var pdf = new jsPDF('p', 'pt', [canvas.width, canvas.height]);
var imgData = canvas.toDataURL("image/jpeg",1.0);
pdf.addImage(imgData, 0, 0, canvas.width, canvas.height);
pdf.save('image.pdf');
});
}
Any guess why that color is overlapping? Any other solution to render HTML to pdf?
maybe my answer help someone. I resolved similar issue by adding a scale property
html2canvas(document.querySelector('#preview_modal'), {
allowTaint: false,
useCORS: true,
scale: 2,
})

Video tag in electron

I'm trying to play videos (mp4) in an window loaded with Electron.
Weird thing : it works fine with only one video, with the others it shows a black screen. The only difference between all videos are their width and height (does that matter ?). Also, in a browser window all videos play just fine.
Here's the code that load windows in electron :
let mainWindow;
let playerWindow;
app.on('window-all-closed', function() {
if (process.platform != 'darwin') {
app.quit();
}
});
app.on('ready', function() {
mainWindow = new BrowserWindow({
title: 'MasterGameApp',
x: 910,
y: 500,
width: 800,
height: 460,
show: true,
resizable: false,
transparent: false
});
playerWindow = new BrowserWindow({
title: 'playerView',
x: 2250,
y: 50,
width: 1005,
height: 540,
show: true,
transparent: false,
fullscreen : true
});
mainWindow.loadURL('http://localhost:8889');
mainWindow.setMenuBarVisibility(false);
mainWindow.setAutoHideMenuBar(true);
playerWindow.loadUrl('http://localhost:8889/playerView');
playerWindow.setMenuBarVisibility(false);
playerWindow.setAutoHideMenuBar(true);
mainWindow.on('closed', function() {
playerWindow.close();
playerWindow = null;
mainWindow = null;
});
});
The videos url are simply given to a video tag inside a JS script like this $('#someDiv').append('<video id=\'backgroundvid\' autoplay><source src=\''+ content +'\' type=\'video/mp4\'></video>');
I don't understand why the browser can play every video but the electron window can't ... Thank's in advance
Ummm hey. I just saw the beginning of your URL property for the video tag is out of the inverted commas.
What you have:
$('#someDiv').append('<video id=\'backgroundvid\' autoplay><source src=\''+ content +'\' type=\'video/mp4\'></video>');
What you should have:
$('#someDiv').append('<video id=\'backgroundvid\' autoplay><source src="\''+ content +'\' type=\'video/mp4\'"></video>');
Have you tried changing that?
Stay lit; keep doing Electron. I am a great fan of it and can see its potential for future desktop applications. 👍👍👍
NOTE: Also, I am not sure what your CORS settings are or anything, but if it it trying to load videos locally, it may not let you.

jCanvas imageSmoothingEnabled not working

So I am trying to build a game with pixel art in html using jCanvas. However, when I try to disable imageSmoothing in order to leave the pixels sharp, nothing happens.
$(function() {
$('canvas').drawImage({
source: 'http://i.imgur.com/Y2o59.png',
x:400, y:250,
width: 160, height: 160,
imageSmoothingEnabled: false,
});
});
Edit: Added random piece of pixel art to make it easier to test.
Figured it out.
First of all, its imageSmoothing: false, not imageSmoothingEnabled: false.
Second, you still need to enable smoothing on the context, like this:
var ctxbgd = document.getElementById('background').getContext("2d");
ctxbgd.imageSmoothingEnabled = false;
ctxbgd.webkitImageSmoothingEnabled = false;
ctxbgd.mozImageSmoothingEnabled = false;
There, no smoothing.

spin.js not showing up on iPhone/iPad

I use spin.js for showing a spinner when loading a new page. Because IE had problems with animating a gif I use this library. Now I found out that it doesn't work on iOS. The spinner is not showing up at all. Tested with:
iPhone with iOS 6.1.3
iPad with iOS 5.1.1
It is working on every browser for Windows (even Safari for Windows).
Header:
<script type="text/javascript" src="../js/spin.min.js"></script>
before closing body:
<div id ="center" style="position:fixed;top:50%;left:50%"></div>
<script>
var opts = {
lines: 13, // The number of lines to draw
length: 8, // The length of each line
width: 4, // The line thickness
radius: 11, // The radius of the inner circle
corners: 1, // Corner roundness (0..1)
rotate: 0, // The rotation offset
direction: 1, // 1: clockwise, -1: counterclockwise
color: '#000', // #rgb or #rrggbb or array of colors
speed: 1, // Rounds per second
trail: 60, // Afterglow percentage
shadow: false, // Whether to render a shadow
hwaccel: false, // Whether to use hardware acceleration
className: 'spinner', // The CSS class to assign to the spinner
zIndex: 2e9, // The z-index (defaults to 2000000000)
top: 'auto', // Top position relative to parent in px
left: 'auto' // Left position relative to parent in px
};
var target = document.getElementById('center');
var spinner = new Spinner(opts);
$("#select-place input").click(function(){
spinner.spin(target);
});
$(window).bind("load", function() {
spinner.stop();
});
</script>
I tried to use another element. Here it works. The problem is position:fixed. I read that iOS 5 does support this. How do I center the spinner in the middle of the screen even on iOS? The page is not expliciitely build for mobile devices. It's mainly a desktop version but it should work for iOS too.
Because the other solution didn't worked and I won't use a framework I came up with a JS solution. Simply calculate the middle of the screen with JS:
jQuery.fn.center = function () {
this.css("position","absolute");
this.css("top", Math.max(0, (($(window).height() - $(this).outerHeight()) / 2) +
$(window).scrollTop()) + "px");
this.css("left", Math.max(0, (($(window).width() - $(this).outerWidth()) / 2) +
$(window).scrollLeft()) + "px");
return this;
}
$('#center').center();
Taken from the answer from Tony in this post.
One disadvantage: The user can scroll away from the spinner. You'd need something which adapts on scrolling as e.g. shown in Fixed positioning in Mobile Safari.

HTML 5 Canvas jCanvas/KineticJS when image is draggable, canvas/stage is unresponsive for clicks/touch on an iPad

I've tried this with both jCanvas and KineticJS. When an added image is made draggable:
var image = new Kinetic.Image({
image: imageObj,
id: imageName,
x: parseInt(CoordX),
y: parseInt(CoordY),
draggable: true
});
The canvas/stage become unresponsive for clicks on an iPad.
The only place where it recognises click/tap is on the border.
Has anyone faced similar issue and how did you resolve this?
UPDATE: #user1950497, for jCanvas, the key to making an image draggable is to make sure to set the layer property to true (http://jsfiddle.net/dksmiffs/YdPpy/):
$("canvas").drawImage({
source: "http://upload.wikimedia.org/wikipedia/commons/thumb/d/d8/Gadsden_flag.svg/320px-Gadsden_flag.svg.png",
x: 200, y: 150,
layer: true,
draggable: true
});
Thanks to #Caleb531 who guided me to the answer in jCanvas issue #74.