Plupload Create multiple sized thumbnails - image-uploading
I have found this thread on creating and uploading thumbnail images client side. The tread shows how to upload the first image then follow up by resizing it and uploading again. I was wondering if there is an easy way to add another step so the end result would produce and original, medium size and thumbnail
A better solution is to trigger QueueChanged in the FileUploaded handler, and then call refresh. This will initiate the upload again for the same file and you can set a property that you read in the BeforeUpload handler to adjust the file size.
Warning #1: you should upload the thumbnail after the full-sized image, otherwise the full-sized image may have some buffer issues and get cut off.
Warning #2: This will only work if the bind call for FileUploaded happens after uploader.init(), otherwise the uploader's own handler for FileUploaded will overwrite file.status back to DONE after your handler.
below is the original response from this thread Plupload Thumbnail
uploader.bind('BeforeUpload', function(up, file) {
if('thumb' in file)
up.settings.resize = {width : 150, height : 150, quality : 100};
else
up.settings.resize = {width : 1600, height : 1600, quality : 100};
}
uploader.bind('FileUploaded', function(up, file) {
if(!('thumb' in file)) {
file.thumb = true;
file.loaded = 0;
file.percent = 0;
file.status = plupload.QUEUED;
up.trigger("QueueChanged");
up.refresh();
}
}
is quite simple, I did that in my project, with two minor adjustments.
In the upload.php I made the directory information dynamically:
$diretorio = $_REQUEST["diretorio"];
$targetDir = 'upload/'.$diretorio;
and changed the code in the upload interface:
uploader.bind('BeforeUpload', function(up, file) {
if('thumb' in file){
//thumb
up.settings.url = 'upload/upload.php?diretorio=thumbs',
up.settings.resize = {width : 100, height : 75, quality : 60};
// medium size
up.settings.url = 'upload/upload.php?diretorio=medium',
up.settings.resize = {width : 200, height : 150, quality : 60};
}else{
up.settings.url = 'upload/upload.php?diretorio=full-size',
up.settings.resize = {quality : 100};
}
uploader.bind('FileUploaded', function(up, file) {
if(!('thumb' in file)) {
file.thumb = true;
file.loaded = 0;
file.percent = 0;
file.status = plupload.QUEUED;
up.trigger("QueueChanged");
up.refresh();
}
});
});
the answer given by Eduardo de Souza is very useful to me but there some change to work this code here can't upload medium file and the other is image can't be resize as resize param given i found some changes in my case which is:
var i = 1;
uploader.bind('BeforeUpload', function (up, file) {
if ('thumb' in file) {
if (i == 1) {
//thumb
up.settings.url = 'http://localhost/plupload_new/public_html/upload.php?diretorio=thumb',
up.settings.resize = {width: 80, height: 80, enabled: true};
} else {
// medium size
up.settings.url = 'http://localhost/plupload_new/public_html/upload.php?diretorio=medium',
up.settings.resize = {width: 800, height: 600, enabled: true};
}
} else {
up.settings.url = 'http://localhost/plupload_new/public_html/upload.php?diretorio=full';
}
uploader.bind('FileUploaded', function (up, file) {
if (!('thumb' in file)) {
file.thumb = true;
file.loaded = 0;
file.percent = 0;
file.status = plupload.QUEUED;
up.trigger("QueueChanged");
up.refresh();
} else {
if (i < 2) {
i++;
file.medium = true;
file.loaded = 0;
file.percent = 0;
file.status = plupload.QUEUED;
up.trigger("QueueChanged");
up.refresh();
}
}
});
});
have added a attribue enabled:true in resize param which make image resize and some checking with i variable for geting notice on medium url also,
i think this can be useful.
Related
How to set column width to minWidth when resized width is less than minWidth?
As the code bellow, column don't resize when width is less than minWidth. How can i resize it to minWidth? var passMinMaxCheck = !resizeSets || resizeSets.every(function (columnResizeSet) { return _this.checkMinAndMaxWidthsForSet(columnResizeSet); }); if (!passMinMaxCheck) { // even though we are not going to resize beyond min/max size, we still need to raise event when finished if (finished) { var columns = resizeSets && resizeSets.length > 0 ? resizeSets[0].columns : null; this.fireColumnResizedEvent(columns, finished, source); } return; // don't resize! }
Using the TYPO3 crop function for cs_seo social media images
I am using TYPO3 7LTS with Ext:cs_seo and want to crop the social media images. Unfortunately my approach via file:current:crop doesn't work: page.meta { twitter:image.stdWrap.typolink { parameter.stdWrap { cObject.file > cObject.file { import { preUserFunc = Clickstorm\CsSeo\UserFunc\HeaderData->getSocialMediaImage preUserFunc.field = twitter_image ifEmpty.data = path:{$plugin.tx_csseo.social.twitter.defaultImage} // path:{$plugin.tx_csseo.social.defaultImage} } crop.data = file:current:crop height < plugin.tx_csseo.social.twitter.image.height width < plugin.tx_csseo.social.twitter.image.width } } } og:image.stdWrap.typolink { parameter.stdWrap { cObject.file > cObject.file { import { preUserFunc = Clickstorm\CsSeo\UserFunc\HeaderData->getSocialMediaImage preUserFunc.field = og_image ifEmpty.data = path:{$plugin.tx_csseo.social.defaultImage} } crop.data = file:current:crop height = {$plugin.tx_csseo.social.openGraph.image.height} width = {$plugin.tx_csseo.social.openGraph.image.width} } } } } Has somebody a clue, how I can fix it? Thank you in advance Bertram
You should either get rid of the line that removes the file settings completely and disable the settings within the file section. So the bad line IMHO should be: cObject.file > Since this destroys the rest of the setup.
html2canvas toDataURL(image/png") return poor image quality
I tried to use html2canvas to get image screenshot byte from website. However, the screenshot result ended with poor resolution. Looking for advice to improve screenshot quality. Thanks.
How about something like this: var $wrapper = $("#yourDiv"); setSize($wrapper, "2000px", "20pt"); html2canvas($wrapper, { onrendered: function (canvas) { var a = document.createElement('a'); a.href = canvas.toDataURL("image/jpg"); a.download = 'filename.jpg'; a.click(); setSize($wrapper, "1000px", "10pt"); } }); function setSize(dv, width, fontsize) { dv[0].style.width = width; dv[0].style.fontSize = fontsize; } This resizes the div and font to bigger size and then shrinks back afterwards.
How do I leave the clicked point highlighted in dygraphs?
I am using the selected shapes to draw a larger diamond shape on my graph. When a user clicks a point. I display the data in another div, but I want to leave the clicked point highlighted. In other words, I want to 'toggle' data behind the points on and off and the clicked points need to show if they are included in the dataset. I believe I have seen this somewhere but I cannot find it. Is there a 'standard' way of leaving a clicked point in the 'highlight' state when you mouse away after clicking? Here is my code. The pointClickCallback is getting the data through ajax and displaying it in another div. That part works. I just want to leave the point highlighted so I know which points I have clicked on. I also need the point to revert back to normal when I click a second time. This is a toggle that allows me to select and unselect points. EDIT: I found the interaction model example but when I add it to my code I lose my pointClickCallback functionality. I saw the call to captureCanvas and the interaction model structure. var g = new Dygraph(document.getElementById('rothmangraph'), lines, { //showRangeSelector: true, title: "Personal Wellness Index (PWI)", labels: ['Date', 'Index'], color: ['#006699'], valueRange: [0, 101], axisLabelFontSize: 12, drawPoints: true, gridLineColor: "#aaaaaa", includeZero: true, strokeWidth: 2, rightGap: 20, pointSize: 4, highlightCircleSize: 8, series : { Index: { drawHighlightPointCallback : Dygraph.Circles.DIAMOND }, }, axes: { y: { pixelsPerLabel: 20, }, x: { valueFormatter: function(ms) { return ' ' + strftime('%m/%d/%Y %r',new Date(ms)) + ' '; }, axisLabelWidth: 60, axisLabelFormatter: function(d, gran) { return strftime('%m/%d %I:%M %p',new Date(d.getTime())) ; } } }, underlayCallback: function (canvas, area, g) { var warning = g.toDomCoords(0,41); var critical = g.toDomCoords(0,66); // set background color canvas.fillStyle = graphCol; canvas.fillRect(area.x, area.y, area.w, area.h); // critical threshold line canvas.fillStyle = "#cc0000"; canvas.fillRect(area.x,warning[1],area.w,2); // warning threshold line canvas.fillStyle = "#cccc00"; canvas.fillRect(area.x,critical[1],area.w,2); }, pointClickCallback: function(e,point) { var idx = point.idx; var line = lines[idx]; var sqltime = strftime('%Y-%m-%d %H:%M:%S',new Date(line[0])); var dispdate = strftime('%m/%d %r',new Date(line[0])); _secureAjax({ url: '/ajax/getDataPoint', data: {'patient_id': pid, "rdate": sqltime}, success: function (result) { // parse and add row to table if not exists. var data = JSON.parse(result); var aid = data['id']; var indexCol = "#a9cced" if (line[1] <= 65) indexCol = "#ede1b7"; if (line[1] <= 40) indexCol = "#e5bfcc"; var headerinfo = '<th class="'+aid+'"><span class="showindex" style="background-color:'+indexCol+'">'+line[1]+'</span></th>'; var fixdate = dispdate.replace(' ','<br>'); var headerdate = '<th class="'+aid+'">'+fixdate+'</th>'; // skip if already exists var found = false; var whichone = false; $('#headerdate tr th').each(function(idx, item) { if (fixdate == $(this).html()) { found = true; whichone = idx; } }); if (!found) { $.each(data, function (idx, item) { $('#' + idx).append('<td class="'+aid+'" style="width:70px">' + item + '</td>'); }); $('#headerdate tr').append(headerdate); $('#headerinfo tr').append(headerinfo); } else { $('tr').each(function() { $('.'+aid).remove(); }); } } }); } }); }
html2canvas loading issue when saving the image
I am using the following code to save the content of div (image and text) as an image using html2canvas. $(function() { $("#save").click(function() { var flag = true; var imgpath = document.getElementById('file').value; if(imgpath.length == 0) { alert('Please select image file to upload.'); flag = false; } else { html2canvas($('.body740'), { onrendered: function(canvas) { theCanvas = canvas; var url = canvas.toDataURL("image/png"); var br = document.createElement("br"); var center = document.createElement("center"); var newImg = document.createElement("img"); // create img tag newImg.src = url; $(".body740").hide(); $("#canvas").show(); //div where the final image is shown document.getElementById("rsimg").src=url; document.getElementById("rsa").href=url; } }); } }); }); This is my link : http://www.aamras.com/greetings2/ But, when I click the save image button, it takes a lot of time to generate the image. Why is it taking so much time to load? What is the issue?
Solved : Change the version of html2cannvas. I was previously using html2canvas 0.5.0-alpha 2014 version I Switched to html2canvas 0.5.0-alpha1. It generates the image properly and takes no time to do so. You can download the files from https://github.com/niklasvh/html2canvas/releases