How to save drawn image with a background color using Signature Pad library for AngularJS/Ionic? - angularjs

I'm working on an Ionic project and implemented this library to handle the drawing of a client signature.
I've managed to implement this with no problem, I can draw, save and show the image with no problem, except one detail: the image is saved with a transparent background.
By default, the image is saved as a PNG file, which is something desired on my end, but it needs to have a white background. The library states that the backgroundColor can be set to any non-transparent color, but only works for JPEG images, and indeed I tried this for a PGN image and it got saved with a transparent background.
I tried to apply a background color to my canvas on my CSS, but when the image is saved the background color isn't applied to the image. I know I could just display on a white background, but it's part of our requirements for it to have a white background.
This is how my template for drawing the signature:
<ion-modal-view class="signature-modal">
<div class="button button-clear signature-close-button" ng-click="closeSignatureModal()"><span class="icon ion-close"></span></div>
<div class="signature-container">
<div class="signature_canvas_container">
<canvas id="signature-pad" class="signature-canvas"></canvas>
</div>
<div class="signature-container-separator"></div>
<div class="row signature-buttons-container">
<div class="col col-11"></div>
<div class="col col-33">
<button class="button button-full button-light" data-action="clear" ng-click="clearSignature()">Limpiar</button>
</div>
<div class="col col-12"></div>
<div class="col col-33">
<button class="button button-full button-positive" data-action="save" ng-click="saveSignature()">Guardar</button>
</div>
<div class="col col-11"></div>
</div>
</div>
</ion-modal-view>
My style for the canvas is this:
.signature-canvas{
width : 100%;
height : 100%;
background-color: white;
}
The configuration properties for the signature pad are these:
canvasPad = document.getElementById("signature-pad");
$scope.resizeCanvas();
signaturePad = new SignaturePad(canvasPad);
signaturePad.minWidth = 1;
signaturePad.maxWidth = 1.5;
signaturePad.dotSize = 3;
signaturePad.backgroundColor = "rgb(255, 255, 255)";
signaturePad.penColor = "rgb(66, 133, 244)";
Saving it is done like this:
var rawImage = signaturePad.toDataURL();
Am I missing something? Can PNG images be saved with a background color?
EDIT
I changed the background color to rgb(0, 125, 255) and the canvas didn't change the color, thought it was my CSS and removed the background-color property from there and still the canvas was shown as white, the color from the CSS is used but that doesn't affect the background for the image. Why isn't rendering the canvas with the background set on the signature pad's properties? No matter where I put the background color, either the CSS or the pad's properties, no color is applied to the image signature I save.

I checked the Draw over image example from the author's page and the way he instantiated the SignaturePad gave away a solution for this issue:
var signaturePad = new SignaturePad(document.getElementById('signature-pad'), {
backgroundColor: 'rgba(255, 255, 255, 1)',
penColor: 'rgb(0, 0, 0)'
});
If you set the background color like this, instead of doing signaturePad.backgroundColor = 'rgba(255,255,255,1)', then the background color takes effect and when you save the image and you display it later it will be shown with a background color.
Although if you require to change the background color after the SignaturePad is instantiated, then I might suggest dismissing and recreating the canvas again, since setting the background color property after creating the instance of the SignaturePad doesn't affect the color.

Related

How to display RGB color picked up from Json in React.js?

I write the code like below,
I got the color data by integer like this.
255255255
enter image description here
However, I want to show like the picture below
(how I call this? color something? it's not color picker)
enter image description here
The picture is the screen of the mobile app, and I would like the web app to have the same design as the mobile app as much as possible.
Is such an expression possible in React.js?
If it is possible,
how?
Json
"mode": {
"rgb_color": [
255,
255,
255
],
}
React.js
{schedules.map(schedule => (
<div className="each_scheduled" key={schedule.id}>
<div>
<p className="scheduled_p">Color</p>
<p className="scheduled_p">{schedule.mode.rgb_color}</p>
</div>
</div>
))}
If I correctly understood your question you can just set the color in inline styling:
<p className="scheduled_p" style={{ backgroundColor: `rgb(${schedule.mode.rgb_color.split(',')})` }}></p>

Change the font of HTML5 Canvas using a button in Angular.js

I want to change the font of my HTML canvas using a button.When I will click in this button, a function in my angularjs file will trigger and the font will be changed.But nothing actually happening here.The font is not changing at all.I can change the background color but not the font.
Code of HTML part
<button type="button" id="btn" ng-click="changefont()">Font</button>
<div>
<canvas ng-style="mybody" id="myCanvas" style="border:1px solid #d3d3d3;">
Your browser does not support the HTML5 canvas tag.</canvas>
</div>
Code of Angular.js part
$scope.changefont=function(){
$scope.mybody = {
"font" : " 15px sans-serif",
"background-color" : $scope.bcname
}
console.log("fontclick");
}
in another function I have code for canvas
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.fillText(strings, 100, 100*(i+1));

Angular Material md-grid-tile width and height become 0 after background-image url change

I encounter a very strange problem of Angular Material Gird List (1.0.0-rc2 - the latest Angular Material). I have a Grid List with 3 elements with background images. Everything load correctly after the initial page load. I have a delete button in each element. When click, it empty out the background image url value. After I click the delete button and empty the background image url value, the associated grid tile lost its width and height. The inside element just float to the top left and the layout is all broken. Here is codepen to illustrate the problem:
http://codepen.io/hughred22/pen/GpXZgy
As you see after clicking the delete button, the red text will lost its position and float to the top left. If you exam the tile, it has 0 width and height.
Here is the HTML code of the md-grid-list:
<md-grid-list md-cols="6" md-cols-sm="6" md-row-height="1:1" md-gutter="0px" md-gutter-gt-sm="0px" style="background: black;">
<md-grid-tile md-rowspan="3" md-colspan="2" md-colspan-sm="2" style="background-image: url({{vm.picturesObj[0].photo}}); background-size: cover;" class="top-tile-edit">
<p style="color: red; font-weight: bold;">The Text which is representing the inside elements. It align center when loaded.</p>
<md-grid-tile-footer>
<md-button type="button" class="md-raised md-warn" ng-click="vm.deleteAddedPhoto(vm.picturesObj[0].photo)">
Delete
</md-button>
</md-grid-tile-footer>
</md-grid-tile>
<md-grid-tile md-rowspan="3" md-colspan="2" md-colspan-sm="2" style="background-image: url({{vm.picturesObj[1].photo}}); background-size: cover;" class="top-tile-edit">
</md-grid-tile>
<md-grid-tile md-rowspan="3" md-colspan="2" md-colspan-sm="2" style="background-image: url({{vm.picturesObj[2].photo}}); background-size: cover;" class="top-tile-edit">
</md-grid-tile>
</md-grid-list>

how to make rounded input field in ionic?

I am able to make input field with icon but I need the input field should be rounded corner ![enter image description here][1] and horizontally center width smaller as show in image .
please check the below image
Please check my search bar is smaller in width and horizontally centered having rounded corner .can we make this in ionic
here is my code
<ion-content>
<div class="list list-inset">
<label class="item item-input">
<img src="https://dl.dropboxusercontent.com/s/n2s5u9eifp3y2rz/search_icon.png?dl=0">
<input type="text" placeholder="Search">
</label>
</div>
</ion-content>
The answer is simple
first you need to put all you need inside ion-item tag and then you need some css properties to shape that ion-item
Example
HTML CODE :
<ion-item class="roundedInput">
<ion-label position="floating">Rounded Input</ion-label>
<ion-input></ion-input>
</ion-item>
CSS Code :
.roundedInput {
--border-color: var(--ion-color-medium-shade);
--border-radius: 3px;
--border-width: 1px;
--box-shadow: 2px gray;
--highlight-height: 0;
--background: #f8f9fa;
}
to take control of the item behavior you need some more CSS Codes
like this :
.roundedInput.ion-invalid.item-has-focus {
--border-color: var(--ion-color-danger-shade);
}
.roundedInput.ion-valid.item-has-focus {
--border-color: var(--ion-color-success-shade);
}
.roundedInput.ion-invalid.ion-dirty {
--border-color: var(--ion-color-danger-shade);
}
.roundedInput.ion-valid.ion-dirty {
--border-color: var(--ion-color-success-shade);
}
the label with floating position will increase the input height
if its not what you like , all you need to do is just change the position to static or with no position property.
or you can just use placeholder
Why not just set some attributes to your outer div and your inner label in your .css like
div#container{width: 300px; margin-left: auto; margin-right: auto;}
label#rounded{border-radius: 15px;}
Here's the pen. Is this what you're looking for?

Dojo / Dijit Layouts without Non-Semantic HTML

I'm new to dojo/dijit, coming from a Backbone/Marionette background.
Right now I'm working with dijit's layout system, but I'm kinda shocked by the amount of non-semantic html in the examples needed to get it moving. For example, an accordion (from http://dojotoolkit.org/reference-guide/1.9/dijit/layout/ContentPane.html):
<div data-dojo-type="dijit/layout/AccordionContainer" style="width: 200px; height: 95%; margin: 0 auto;">
<div data-dojo-type="dijit/layout/AccordionPane" title="pane #1">accordion pane #1</div>
<div data-dojo-type="dijit/layout/AccordionPane" title="pane #2">accordion pane #2</div>
<div data-dojo-type="dijit/layout/AccordionPane" title="pane #3">accordion pane #3</div>
</div>
Is there a way to do this without having to add all that into the HTML? Specifically, I'm trying to find the equivalent of 'regions' in dijit layout, so I can include a template for a layout and place views in and out of that easily.
you can create content panes programmatically as in this accordion container example. (AccordionPane is deprecate, just use ContentPane instead)
var accordion = new AccordionContainer({
style: "width: 200px; height: 100%;"
}).placeAt(document.body);
var content = new ContentPane({
title: "content1",
style:"height:100px"
});
accordion.addChild(content);
accordion.startup();
if you need to use regions, bordercontainer's design property gives you that as in this example. you can put an accordioncontainer in one of the content panes there...

Resources