createjs.Shape() with graphics setStrokeStyle(1) draws a 2px line instead of 1px. If you screenshot the JSfiddle output below, you will seee that the line is 2px tall.
http://jsfiddle.net/7fbr9yan/
How do I draw a 1px line?
The line that you draw in going in between two lines of pixels, so it's coloring both sides of it in grey instead of black.
change your code to
line.graphics.moveTo(20,74.5).setStrokeStyle(2).beginStroke("#000").lineTo(280,74.5);
in order to draw over only one line of pixels.
Related
I'm trying to use ImageMagic to open a PDF, draw a couple of boxes with text labels on the PDF, and then resave it as a PDF. This has been deceptively difficult for me to figure out how to do, but I got something working per this previous question: imageMagick: How do I draw on one page of a pdf but keep the whole pdf?
My test files, which were 3 pages, were processed fine. However, when it went to QA, and it was tried with large files (some 30-50 pages, which will be normal use for this script) it kept timing out with messages like this:
timeout [300000 ms] expired while executing [c:\IM\magick.exe -density 300 -compress ZIP c:\tempWorking\138.pdf[0-1] ( c:\tempWorking\138.pdf[2] -fill rgba(255, 214, 214, 0.7) -stroke #000f55 -draw rectangle 2145,742,3245,907 -fill #000 -stroke #000 -font Arial -pointsize 10 -draw text 2167,885 'Box 1: Test' -fill rgba(255, 214, 214, 0.7) -stroke #000f55 -draw rectangle 2145,896,3245,1061 -fill #000 -stroke #000 -font Arial -pointsize 10 -draw text 2167,1039 'Box 2: Test 2' -fill rgba(255, 214, 214, 0.7) -stroke #000f55 -draw rectangle 2145,1023,3245,1188 -fill #000 -stroke #000 -font Arial -pointsize 10 -draw text 2167,1166 'Box 2: Test 2' ) c:\tempWorking\138.pdf[3-18] c:\esigImgs\62\preview.pdf]
To break down that impenetrable wall of text, my script wrote out a command similar to this:
c:\IM\magick.exe
-density 300
-compress ZIP
c:\tempWorking\138.pdf[0-1]
(
c:\tempWorking\138.pdf[2]
-fill rgba(255, 214, 214, 0.7)
-stroke #000f55
-draw rectangle 2145,742,3245,907
-fill #000
-stroke #000
-font Arial
-pointsize 10
-draw text 2167,885 'Box 1: Test'
-fill rgba(255, 214, 214, 0.7)
-stroke #000f55
-draw rectangle 2145,896,3245,1061
-fill #000
-stroke #000
-font Arial
-pointsize 10
-draw text 2167,1039 'Box 2: Test 2'
-fill rgba(255, 214, 214, 0.7)
-stroke #000f55
-draw rectangle 2145,1023,3245,1188
-fill #000
-stroke #000
-font Arial
-pointsize 10
-draw text 2167,1166 'Box 2: Test 2'
)
c:\tempWorking\138.pdf[3-18]
c:\esigImgs\62\preview.pdf
So we're taking some pages that are not altered, adding a page that is altered, then adding more pages that are not altered. Production use of this will usually involve far more boxes and text being written to several pages.
I extended the timeout to 300s just to see what would happen. Originally the timeout was set at 60 seconds, and I would really like it to take far less. This was running on an AWS instance. When I tested it locally it completed in around 60 seconds with the same file, but had mostly locked my cpu for that entire time.
What am I doing wrong and how can I approach making this process more efficient?
In comments you asked how to add vector info quickly to a source PDF via Image Magic appending data, I replied, it is best to use annotation by over stamping one PDF onto another, and there are many different cross platform methods even using shell script as a rect and text pdf as the stamp.
However, it seems from the question your need is even simpler than that.
As an example to add text and boxes you could use cpdf, the advantage is the values can be easily set as variables for different situations. here I am using just page 1 (-range 1) but that same entry can be applied to a range of pages.
cpdf -add-rectangle "200 100" -pos-center "180 200" -color "red" -range 1 -outline earth.pdf AND -pos-center "180 210" -midline -font Helvetica -font-size 20 -add-text "Hello World!" -color "white" -opacity 1.0 -range 1 AND -pos-center "180 190" -midline -font Helvetica -font-size 20 -add-text "Hello USA!" -color "1.0 1.0 0.0" -opacity 1.0 -range 1 -o out.pdf
For more complex possibilities like multi line stamps there is a powerfully small cross platform tool at https://pdfcpu.io/core/stamp#examples
As the screenshot shows, the width and height value can only be px values. How can I make them to be fixed ratio such as 16:9 or 4:3?
I'm working with a shapefile converted from a raster with lots of little holes in it, therefore, the borders create big splodges in the shape when plotted.
I'm currently adding the polygon to the main plot with the below code. Despite setting the alpha value to 1 the colours are different even when both set to "red" which makes no sense to me.
geom_sf(data = filter(db, band == 9), aes(fill = "red"), colour = "red", alpha = 1)
Can I either:
Set the borders to the same colour as the fill?
Or remove the border entirely?
Or set the border colour to none?
How to draw a rectangle in easeljs with only two rounded corners. I am doing this to get rounded corners in the bottom:
layout.graphics.beginStroke("black").drawRoundRect(100,100,100,100,0,0,5,5);
This is not drawing any rounded corners. Only this seems to be working:
layout.graphics.beginStroke("black").drawRoundRect(100,100,100,100,5);
Look into the drawRoundRectComplex method, instead of drawRoundRect: http://createjs.com/docs/easeljs/classes/Graphics.html#method_drawRoundRectComplex
drawRoundRectComplex(x, y, w, h, radiusTL, radiusTR, radiusBR, radiusBL);
Hope that helps.
I need some help with OpenGL textures masking. I have it working but need to find some other blending function parameters to work in other way.
Now I have:
//Background
...code...
glBlendFunc(GL_ONE, GL_ZERO);
...code
//Mask
...code...
glBlendFuncSeparate(GL_ZERO, GL_ONE, GL_DST_COLOR, GL_ZERO);
...code...
//Foreground
...code
glBlendFunc(GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA);
...code
Now it sets foreground's opacity to 0 (fills with background texture) where mask is transparent. I need it to react to mask's colors. I mean something like setting foregrounds opacity depending on mask's color. For example if mask is black (0.0,0.0,0.0) then the opacity of that place in foreground is 0 (is filled with background), and if mask is white (1.0,1.0,1.0) then the opacity of foreground is 1 (not filled with background). It can be in reverse consequence (white = opacity 0, black = opacity 1). I just need it to work depending on color.
My current result's visualization bellow.
Background:
Mask (circle is transparent):
Foreground:
Result:
And I want it to work like this:
Background:
Mask (circle is white, background is black):
Foreground:
Result:
So that later it could be used like this:
Background:
Mask (circle is white, background is black):
Foreground:
Result:
Attempt with #Gigi solution:
Perhaps this is what you want:
1) Clear the destination image:
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
2) Draw the background, masking out the alpha channel:
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_FALSE);
3) Draw the "masking overlay", masking out the color channels:
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_TRUE);
4) Draw the foreground, enabling blending:
glEnable(GL_BLEND);
glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_ADD);
glBlendFuncSeparate(GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA, GL_ONE, GL_ZERO);
Note: The overlay image must have the alpha channel specified.