crop an image into a circle rmagick + rails - css

I am a newbie to RoR and for a feature we need to resize and crop images into circular/oval shaped images. I am using Carrierwave gem to upload them and rmagick(2.1.2) to modify the images on rails 4.1 platform.
On top of that, we need to dynamically mask the images with some color(saved in the modal, every image would have different color based on certain parametes.) before rendering them.
For the first part, I am trying this:
def crop_large
manipulate! do |source|
source = source.resize_to_fill(450,450).quantize(256,Magick::GRAYColorspace).contrast(true)
canvas = Magick::Image.new 450,450
gc = Magick::Draw.new
gc.fill "black"
gc.circle 225,225,5,225
gc.draw canvas
mask = canvas.blur_image(0,1).negate
mask.matte = false
source.matte = true
source.composite!(mask, Magick::CenterGravity, Magick::MultiplyCompositeOp)
end
end
But this leaves black borders and I don't know how to get rid of them. Any clues on how should I fix this?
Also, I don't know how to get the 2nd part done.

Sounds like you are having styling issues, fix it with css by adding a class or two,
it will be much easier.

Related

Zoom & crop an image and draw an svg-square on top (in angular)

"A stackblitz is worth a thousand words": https://stackblitz.com/edit/angular-zoom-crop-marker
Basically what I'm trying to do is to have a square drawn above a certain position in an image (<img>), and have that dynamically adjust to the image while being zoomed in / out and cropped. The stackblitz link has 3 views, the basic view which is a plain image, a zoomable view (which I got working as well) and a view where the imaged is "zoomed in and cropped" while being zoomable - This is where I need your help.
Should I crop using object-fit in some way? Is it better if I use a canvas to handle this? I've been at this for a whole day I and I feel my css knowledge is too limited to pull this of.
Bonus question: How would I go about to have the zoom-in zoom-out buttons add/remove one image per row using only css flex-box? (ie: not statically adding x pixles in height and width, but rather increase or decrease the size of each image so that another image is removed or added (per row) while always filling up all the available space)
Thank you in advance!
Managed to solve it myself. stackblitz updated with a working solution.

Sikuli gets confused between 2 identical buttons

I have identical buttons on the same page and I want Sikuli to click only one of those but it ends up clicking the other name sake button. Unfortunately, the button names cannot be changed. Any suggestions on how I could handle this situation?
Thanks!
You can tell Sikuli to operate on a particular region on the screen relative to a given image/screenshot object. This is called TargetOffset. Refer here assuming you are asking about using sikuli programmatically. From Sikuli IDE, double click on the screenshot image and it brings up a window where you can set accuracy and targetOffset.
If the two icons are close together, and will always appear the same way, and the space between them will always appear the same, then a
click(imageOfTwoIcons).targetOffset(x,y)
is probably the simplest way to go. But, if there is anything that would make this method unreliable (anything between the two icons ever appears differently than when you are making your screen capture of them)--
You could also use the python sorted() function to sort the images by their position. For example, if one image is always above the other, then you could find both images and sort them by their y coordinate, like so:
#a little prep for the sorted function to get the y coord of the icon
def byY(icon):
return icon.y
#findAll() on your two identical icons and make them into a list
bothIcons = list([x for x in findAll(icon)])
#then sort them
sortedIcons = sorted(bothIcons, key=byY)
iconOnTop = sortedIcons[0]
iconOnBottom = sortedIcons[1]
#then click on the one you want
click(iconOnTop) #or save a line and say: click(sortedIcons[0])
The same can be done if you know that the icon of interest is always left or right of its twin:
def byX(yourTwoImages):
return image.x
bothIcons = list([x for x in findAll(icon)])
sortedIcons = sorted(bothIcons, key=byX)
click(sortedIcons[0]) #for the image on the left
I like this better than working with regions if the two icons are very close together on the screen, or if it's possible for the icons' placement to ever change.
you can enlarge the buttons image, so that the image will include more than just the image, but also the background around it (if you can be sure that the background is not changing) but remember that sikuli clicks on the center of the image, so make sure that the button is in the center.
another option is to click using offset (http://doc.sikuli.org/tutorials/checkone/checkone.html)
use something like this:
this.offset = 15;
org.sikuli.script.Region reg = screen.find("image").left(this.offset);
screen.click(reg);

Finding color on flex page

I want to find some color on flex page exists or not?
For example
if(red color exists on page){
Alert.show("red exixts");
}else{
Alert.show("red does not exists");
}
so before writing this if else block,i need to find the red color(any where on flex page)
Note:- My page do not hav any images.with images i m getting the color.My page has a canvas and hboxes and diff texts with diff colors.
Done with bitmap,bitmap data.....NO LUCK :( Please help me wit this
Draw your page (application?) into bitmap. Then analyze each pixel (may take time). What red do you need? If you accept not only pure red (0xFF0000), define minimum level for red channel and maximum for other channels. As soon as "red" pixel is found, quit checking.
I would suggest that you start iterating over all the children objects of the application, get the colour property, using getStyle("propertyname"), and you will find the colour of all possible objects.This is much better than rendering the whole app, into a bitmap and then testing for each pixel.

change Preloader background color

I have a custom preloader that I designed in flash. When I load it in flex, it loads with a white background. When I try to change the background to black in my flash file & load it in Flex, the background color remains white. I've also tried to update the compiler settings in Flex, adding "-default-background-color #000000" but I still get a white preloader background. I am using Flex 4. Here is my Pre.as file:
`
`
thx!
I encountered the same problem.
solved it using opaqueBackground :
loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.INIT, init);
private function init(e:Event):void{
loader.opaqueBackground = 0x000000;
}
Worked great for me.
This man solved it by adding background sprite and filling it with custom color you want.
And here http://iamjosh.wordpress.com/2007/12/18/flex-custom-preloader/ author also told that he added the compiler option like this:
Finally, let’s change the background
color of the application to match our
logo a little better. Just add the
following Flex compiler argument:
-default-background-color #FFFFFF
So, you might added this option to another one application you need instead.
UPDATE 1
Also look at this
http://cookbooks.adobe.com/post_Change_Background_Color_of_the_Preloader_Phase-1421.html
And please, explain once again your goals, are you want to set color or something another, from preloader or parent application or whatever you want, just let me know.
UPDATE 2
And listen, if you really want some cool bg, you might do next thing.
1)Forget about preloader mechanism.
2)Write Your BG application
3)Add swfLoader overlay to your bg application
4)Draw progressbar for this container
5)Enjoy with 2 application architecture instead of standard way.
Questions!?

AS3: grouping sprites

I have a handful of sprites that I am attempting to group together via addChild().
Here is some pseudo-code demonstrating what I would like to accomplish:
import nav.text.TextSprite;
spr1:Sprite = new Sprite();
spr1.graphics.clear();
spr1.graphics.beginFill(0x000000);
spr1.graphics.drawRect(0,0,100,100);
txt1:TextSprite = new TextSprite;
txt1.text = "hello";
spr1.addChild(txt1);
//this is what isn't working: the sprite is hidden but not the text
spr1.alpha = 0.0;
For some reason I cannot seem to get the TextSprite to draw correctly... All it is is a Sprite with a TextField added to it. I think everything is working there, but I might have something wrong w/r/t making sure all of TextSprites children are grouped correctly.
I should mention that it does position correctly; but the alpha property won't respond in the way I would expect it to. I.E., the sprite that the TextField is attached to will allow it's alpha to be set but the text remains visible.
Any thoughts?
Most likely you just need to embed the font in your textfield. Try changing the x, y of spr1 and see if txt1 moves along with it. If it truly is a child then it will respond to the new position.
You need to embed the font using textfield.embedFonts = true. If your text is disappearing when you do this, how are you going about embedding the font (using the Flex embed meta tag or using the Flash IDE?), check that you are not changing the font weight (setting the text to bold when you have only embedded the normal weight font) and if you are using a text format, be sure to apply the text format AFTER you set the textfield.text property. You can get around this by using textfield.defaultTextFormat.

Resources