Konva.js How to drag images and resize with Transformer? - konvajs

I'm trying to drag and drop these images to the stage.
but when I dropped images, I received this error. Konva.js Konva error: Can not cache the node. Width or height of the node equals 0. Caching is skipped.
The process that I thought of was
drop the image into stage
If it is clicked, users can resize, rotate, drag.
What should I do differently to successfully resize images?
https://codesandbox.io/embed/magical-meitner-7gic1?fontsize=14&hidenavigation=1&theme=dark

Make sure you cache a shape when image is loaded.
useLayoutEffect(() => {
if (image) {
shapeRef.current.cache();
}
}, [shapeProps, image, isSelected]);

Related

Changing image/textures of a SKSpriteNode with different sized images

I have a large number of small images that I am swapping between in a SKSpriteNode object. The problem is it seems to establish a set container size and other images will stretch to fit the container. Is there a way to reset this each time? Or do I have to modify all the images to be the same size? I was hoping it could just display them as the true image size and I could keep it centered as they are all already centered as they are.
I basically just update the texture each time I do it. Is there a flag or property I am not setting correctly?
When a SKSpriteNode is first created, its texture/image size is set. I suggest you take the largest x and y values in your animation sequence and set all pics to the same (largest) size. You can use a transparent background for each pic.

can image view resize itself according to the image it contains in iOS

i have to add a number images to the view. the images i have from the designer are of correct size. it would speed up my work if i don't have to manually size each image-view as per size of the image and then select the image ( which anyways contains the right dimensions )
is there a way in which i can put an image-view of any size select image property and then select an option that would resize the image-view as per image
You can set their content mode to a position like center, left, right, top, bottom... That way the image will keep its original size.
You just need to make sure that the imageview is large enough to display the image, so it doesn't get cropped.
I don't know exactly what your designer provides you in terms of position of the elements, but it's probably the top left position, so use the Top Left mode so that the image within the imageview hugs the top left corner and keeps its original size.

SDWebImage resize image

I am using the SDWebImage library in order to download and cache images. In my application, each user has an avatar which can be displayed in different shapes and sizes (circle, square ...).
Right now i am downloading the image, and when i get it i resize it according to the image view size.
But i think this approach is inefficient and specially when scrolling in a table view.
Is there a different approach (concerning SDWebImage) that allows me to get the image in the desired size without having to resize it my self ?
Thanks.
You can resize image once and store it in a cache (SDImageCache). Then load it from this cache. There is no way to get the image in the desired size without having to resize it yourself, unless such image of desired size exists on the server.

iOS swipe filters over static image

I'm looking for a way to swipe image filters over top of a still image.
Mainly the base image stays in place, and the filters slide in over top when you swipe left or right.
Right now I have a base UIImageView and a Collection View over top of it which in theory would hold the filters (texture and gradient images).
I've read that UIImageViews and UIViews can't be live composited on top of each other, and that you must make the image before displaying it. So I can pre-make the image beforehand in code, then can I wipe-reveal the filter image to get the same effect? Using masks?
Code examples are nice, but a high level description on how to approach this would be helpful.
The app Spark has this functionality for videos, I'm looking to do something similar for photos.
So I can pre-make the image beforehand in code, then can I wipe-reveal the filter image to get the same effect? Using masks?
Yes, but no need for a mask. Pre-make the filtered image and put it in an image view. Let's say this filtered effect is to be swiped in from the left. Then make the image view's content mode be Left, and put it at the left of the real image, with width zero. As the swipe happens, animate the width of the image view to the width of the image. This will cause the filtered image to be revealed from the left side.

Rmagick resize and flatten_image error

I am trying to use Rmagick to combine two images.
The image on top can be resized and dragged using Jquery-UI. I get size of the image after resize using Jquery code such as follows:
ui.size["height"] and ui.size["width"]
I send this data using Ajax to Rails server.
The next step I resize the image using Rmagick resize_to_fit and then use flatten_image to combine the two images as follows:
images=ImageList.new(img1, img2)
images[1]=images[1].resize_to_fit!(height, width)
images[1].page=Rectangle.new(height, width, x_coord+offset, y_coord-offset1)
com_img=images.flatten_images
com_img.write(tmpfile.path)
My problem is that the resize image does not seem to work correctly. I am always getting an image smaller than what I want (for different heights and widths tested by resizing image). The image's left top corner is correctly placed (meaning page command is working correctly). I checked my Jquery UI code and ajax and its sending the correct size information. Somehow the information is not being processed correctly by Rmagick resize or flatten_image.
Can someone provide pointers what could be wrong here?
Thanks!
PS: Offsets account for the first image's position with respect to page top-left corner.
I found the solution to the problem Rmagick requires the images when they are resized that they should fit into a square. So the resize_to_fit function works correctly when both dimensions are the same and are the larger one among height or width.
So I changed the code to do the following
if height > width
images[1]=images[1].resize_to_fit!(height, height)
else
images[1]=images[1].resize_to_fit!(width, width)
end

Resources