How to add border to the image as polygon/round shaped - fabricjs

We are building the shapes for conveyors, Is there any way to create a rounded border for the images? The below images, which are png files, have square borders around the selected Images.
While Searching we found this code from the link
CSS Border on PNG image with transparent parts
img{
-webkit-filter: drop-shadow(1px 1px 0 black) drop-shadow(-1px -1px 0 black);
filter:drop-shadow(1px 1px 0 black) drop-shadow(-1px -1px 0 black);
}
Is there any way to add drop-shadow to the images in canvas?
Kindly help us with relevant codes and suggestions.

I did this by the properties shadow and strokeWidth(in css by adding shadow). So that image will be like this.
item.strokeWidth = 15;
item.shadow = new fabric.Shadow({color:'red',blur:15,affectStroke:true});
Present Output:
If someone has a better solution kindly brainstorm me.

Related

fabricjs clippath not working as per size

I am trying to apply clippath on image, i am passing rect as clippath to image and size of rect is same as image including scale, still after apply clippath image cropped like clipath is less then what we applied.
i have checked clippath scaled width , height after apply is still same but image is clipped bit small like given in attached image.
var rect = new fabric.Rect({
left: 0,
top: 0,
width: obj.getScaledWidth(),
height: obj.getScaledHeight(),
originX: 'center',
originY: 'center'
});
rect.setCoords();
obj.clipPath = rect;
obj.clipPath.dirty = true;
obj.dirty = true; canvas.renderAll();
My fabric version is 3.4.0.
original image on left side and after apply same size rect as clippath clipped image on right side, actual result should be same size image without any clipped part
one thing i have noticed is cacheHeight and cacheWidth of clipath is less then width and height of clippath. please find below screenshot, is it reason for that, if then what will be solution?

In hummus js how can i draw a filled rectangle with transparent?

How can I draw a rectangle with a transparent color?
I tried the below code. I am using hummusjs for modifying pdf.
cxt.drawRectangle(x,y,width,height,{type: 'fill',
color: '#eeeeee',
opacity: 0.9});
If your intention is to draw a rectangle without fill and only containing borders, try this:
cxt.drawRectangle(x,y,width,height,{type: 'stroke',
color: '#eeeeee',
opacity: 0.9});

About skia antialias

Recently I'm learning skia library(google open source 2d engine,be used on Android and chromium,etc.),Now I want to use it on windows instead of GDI+ dont support clip area with antialias,during it, I find a problem about pixel.
up is set antialias,down is not set antialias
the main code is:
paint.setStrokeWidth(1);
paint.setStyle(SkPaint::kStroke_Style);
paint.setAntiAlias(true);
canvas.drawRect(skrect,paint); //draw up rect
skrect.fTop += 110;
skrect.fBottom += 110;
paint.setAntiAlias(false);
canvas.drawRect(skrect, paint); //draw down rect
As you see,the same rect,if I not set Antialias,the boundary pixel is 1(I set strock width is 1),but if I set Antialias, the boundary pixel is 2,and it become a bit light,although I set color is black.
I dont konw why,anyone can tell me?
thk,
now,maybe I konw.
the skia library canvas should be like Html5`s canvas ,Canvas every line have an infinite thin "line", the width of the line from the center line to stretch,so if we draw a 1px line,in fact,it will fill two of 0.5 pixel point,but the display device dont allow it do that,so it will fill 2 pixel point,and set it color more light to differentiate real 2 pixels .
I will search more material to prove it.
This happens because OpenGL assumes that each pixel is centered at [0.5; 0.5]. The rasterizer have to draw indeed two pixels and interpolate the alpha. Read more here
If you would like to draw sharp 1px lines with antialiasing turned on just offset coordinates of a line or other figure with 0.5f.
For example a point at [10; 10] should have coordinates [10.5; 10.5] and so on

SVG with size in px and percentage?

I'm trying to create an SVG element with a width defined by a percentage of the parent and a fixed value, say 50% + 20px. For normal html elements, in the CSS you can use calc(50% + 20px). Is there an equivalent way to do this for embedded SVGs? Specifically, I'm using snap.svg, though I'm not sure if this capability exists with SVGs in general.
EDIT:
Tried setting <svg> width with percentages and px, which I couldn't get to work. I tried both:
<svg width='calc(50% + 20px)'>...</svg>
<svg width='50% + 20px'>...</svg>
I also tried setting it in CSS:
svg {
width: calc(50% + 20px);
}
It should be possible with the upcoming SVG2 as width etc. become geometry properties and then you can style them with calc

How do I change the style of the legend in Flot?

I have just changed my version of Flot from 0.6 to 0.7, however, when I do this, the legend in my Flot graph changes style. Previously, I had used the "LabelClass" attribute to change the style but on reading the source for 0.7 I see that "labelClass" is no longer an option and I appear to be forced to use the "table" CSS definition that is used throughout the site that I'm working on. Because of this I can't change the site's CSS "table" definition.
Is there another good method for changing the definition of a legend or am I stuck?
Apologies in advance is this is just a newbie question
Kind Regards
It has changed names is all, the new class is legendLabel for the labels and legendColorBox for the color box.
You can see this in jquery.flot.js.
EDIT in response, it seems that the question is how do you style the whole table. Assume your flot placeholder is something like this:
<div id="foo" style="width:600px;height:300px"></div>
Then you can define CSS like this:
#foo > div.legend > table {
border: 2px red solid;
}
See it here in action: http://jsfiddle.net/ryleyb/YkDpG/1/
Another way to style the legend is to use the jQuery .css() (http://api.jquery.com/css/) method after the chart has been plotted.
For example:
$.plot($("#chartFoo"), pieChartData, options);
$("#chartFoo div.legend table").css("border", "1px solid #888888");
$("#chartFoo div.legend table").css("background", "#ffffee");
or:
$.plot($("#chartFoo"), pieChartData, options);
$("#chartFoo div.legend table").css({ border: "1px solid #888888", background: "#ffffee" });

Resources