Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [JavaScript]Jak zmienić skrypt aby w firefox uruchamiał się jednym kliknięciem, W firefoxie trzeba kliknąć dwa razy żeby ten skrypt uruchmić co trzeba
andst
post
Post #1





Grupa: Zarejestrowani
Postów: 1
Pomógł: 0
Dołączył: 27.07.2016

Ostrzeżenie: (0%)
-----


function upload() {
var pliki = document.getElementById("pliki");
var file = pliki.files[0];

var preview = document.getElementById("preview");
preview.src = file.getAsDataURL();
return _resize(preview);
}

function _resize(img, maxWidth, maxHeight) {
var ratio = 1;

var canvas = document.createElement("canvas");
canvas.style.display="none";
document.body.appendChild(canvas);

var canvasCopy = document.createElement("canvas");
canvasCopy.style.display="none";
document.body.appendChild(canvasCopy);

var ctx = canvas.getContext("2d");
var copyContext = canvasCopy.getContext("2d");

if(img.width > maxWidth)
ratio = maxWidth / img.width;
else if(img.height > maxHeight)
ratio = maxHeight / img.height;

canvasCopy.width = img.width;
canvasCopy.height = img.height;
try {
copyContext.drawImage(img, 0, 0);
} catch (e) {
document.getElementById('loader').style.display="none";
// alert("There was a problem - please reupload your image");
return false;
}

canvas.width = img.width * ratio;
canvas.height = img.height * ratio;
// the line to change
//ctx.drawImage(canvasCopy, 0, 0, canvasCopy.width, canvasCopy.height, 0, 0, canvas.width, canvas.height);
// the method signature you are using is for slicing
ctx.drawImage(canvasCopy, 0, 0, canvas.width, canvas.height);

var dataURL = canvas.toDataURL("image/png");

document.body.removeChild(canvas);
document.body.removeChild(canvasCopy);
return dataURL.replace(/^data:image\/(png|jpg);base64,/, "");


}

function resizes() {
var pliki = document.getElementById("pliki");


if(pliki.files!=undefined) {

var loader = document.getElementById("loader");
loader.style.display = "inline";

var file = pliki.files[0];
document.getElementById("orig").value = file.fileSize;
var preview = document.getElementById("preview");
var r = new FileReader();
r.onload = (function(previewImage) {
return function(e) {
var maxx = 156;
var maxy = 104;
previewImage.src = e.target.result;
var k = _resize(previewImage, maxx, maxy);
if(k!=false) {
document.getElementById('base64').value= k;
document.getElementById('upload').submit();
} else {
alert('problem - please attempt to upload again');
}
}
}(preview));
r.readAsDataURL(file);
} else {
alert("Seems your browser doesn't support resizing");
}
return false;
}
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 1)
Kshyhoo
post
Post #2





Grupa: Opiekunowie
Postów: 3 855
Pomógł: 317
Dołączył: 4.01.2005
Skąd: że




Witamy na Forum. Zapoznaj się z panującymi tu zasadami. Dostosuj post do wymagań działu.


--------------------
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 19.08.2025 - 15:03