Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a shadow to the image #806

Closed
niravasher opened this issue Feb 21, 2019 · 40 comments · Fixed by #1507
Closed

Adding a shadow to the image #806

niravasher opened this issue Feb 21, 2019 · 40 comments · Fixed by #1507
Labels
has-pull-request Issues which have a PR open

Comments

@niravasher
Copy link

Please describe the problem (or idea)

What did you expect to see that you didn't?
Add a shadow to the image

Please show us where to look

http://sequencer.publiclab.org/examples/#steps=

What's your PublicLab.org username?

niravasher

Browser, version, and operating system

windows 10 with ubuntu subsystem


Thank you!

Your help makes Public Lab better! We deeply appreciate your helping refine and improve this site.

To learn how to write really great issues, which increases the chances they'll be resolved, see:

https://publiclab.org/wiki/developers#Contributing+for+non-coders
@jywarren

@niravasher
Copy link
Author

Hi, please tell how to proceed with this? @jywarren @VibhorCodecianGupta

@jywarren
Copy link
Member

jywarren commented Feb 21, 2019 via email

@niravasher
Copy link
Author

Hello, do I need to load Image inside this module? @jywarren @harshkhandeparkar ?How to decide in which module, image has to be loaded?

@niravasher
Copy link
Author

niravasher commented Feb 23, 2019

Also I made a new module, kept its inBrowser flag and ui flag to true, made index.js, info.json and Module.js. Required this module in the src/Modules.js file. Is there anything else that I need to do to test that module in my local, because I can't see the shadow module in "more modules" in my browser. @jywarren @harshkhandeparkar

@harshkhandeparkar
Copy link
Member

Nirav can you please open a PR? We can discuss and debug it there.

@niravasher
Copy link
Author

niravasher commented Feb 23, 2019

Umm.... I am sorry, I didn't get you @harshkhandeparkar , I can't see shadow module on my local, why should I open a PR? On my local means that whenever I click on "More Modules", I can't see shadow module to add....

@harshkhandeparkar
Copy link
Member

Niravasher I asked you to open a PR so that I can have a look at the code and debug any errors.

@niravasher niravasher mentioned this issue Feb 23, 2019
4 tasks
@niravasher
Copy link
Author

niravasher commented Feb 23, 2019

Opened a PR , #816 @harshkhandeparkar

@harshkhandeparkar harshkhandeparkar added the has-pull-request Issues which have a PR open label Mar 3, 2019
@niravasher
Copy link
Author

Hey, I was working since yesterday. This is what I have made till now
Screenshot (47)
Now I am trying to add shadow on the top portion of the image. Is this relevant? @jywarren @harshkhandeparkar

@harshkhandeparkar
Copy link
Member

Ya good going. Improvements can be made(if reqd) once the scaffolding is done.

@niravasher
Copy link
Author

What all options should we give to the user in this module?
I mean shadow in the top , left , right , bottom or two sided shadow, three sided shadow, all sided shadow?
As in what should I add in info.json file @harshkhandeparkar

@harshkhandeparkar
Copy link
Member

Maybe the same as CSS shadows use?

@niravasher
Copy link
Author

CSS shadows also give blur effect. That is a bit difficult but will try to do that (maybe i have to change the alpha value of the gradient). So there will be an option for three inputs separated by a space @harshkhandeparkar

@harshkhandeparkar
Copy link
Member

You can implement blur in a follow up pr.

@niravasher
Copy link
Author

Ok, roger that. Also how do we add color to the shadow? @harshkhandeparkar

@harshkhandeparkar
Copy link
Member

Is it of any use?

@niravasher
Copy link
Author

CSS has the option, maybe its not of any use. So it will be just a two input space separated option

@harshkhandeparkar
Copy link
Member

You can add some color let's say #RRGGBB, then you can decrease each of the channels proportionally.

@harshkhandeparkar
Copy link
Member

It will be a string with space separted decimal values for each channel.

@niravasher
Copy link
Author

I don't think a normal person who is not a developer and just wants a shadow would know what is a hexcode

@harshkhandeparkar
Copy link
Member

harshkhandeparkar commented Mar 21, 2019

Ya you can use hex but other modules use decimal. Also we use decimal values for channels in PixelManipulation so parsing hex into decimal will be difficult. That's another problem with hex.

@niravasher
Copy link
Author

Ok for now I am keeping only two inputs, will change anything in the follow up PR. Is that Ok?

@harshkhandeparkar
Copy link
Member

👍

@niravasher
Copy link
Author

        if (options.preProcess) pixels = options.preProcess(pixels); // Allow for preprocessing
        if (options.changePosition) {
           for (var x = 0; x < pixels.shape[0]; x++) {
               for (var y = 0; y < pixels.shape[1]; y++) {
                   let pixel = options.changePosition(
                        pixels.get(x, y, 0),
                        pixels.get(x, y, 1),
                        pixels.get(x, y, 2),
                        pixels.get(x, y, 3),
                        x,
                        y
                    );

                    pixels.set(x+25, y+25, 0, pixel[0]);
                    pixels.set(x+25, y+25, 1, pixel[1]);
                    pixels.set(x+25, y+25, 2, pixel[2]);
                    pixels.set(x+25, y+25, 3, pixel[3]);

                    if (!options.inBrowser && !process.env.TEST) pace.op();
                }
            }
        }
        
        function changePosition(r, g, b, a) {
            return [r, g, b, a];
        }

Just like changePixel function, this function should change the position of the image right 25px and bottom 25px as in pixels.set(x+25, y+25, channels,value). But this doesn't seem to work. @harshkhandeparkar @jywarren help me out here. What am I missing?

@harshkhandeparkar
Copy link
Member

I think when x+25 is not inside the image. I.e. greater then the width of the image and lies outside of it, it throws an error and doesn't work.

@niravasher
Copy link
Author

niravasher commented Mar 22, 2019

Doesn't throw any error in the console @harshkhandeparkar

@harshkhandeparkar
Copy link
Member

Any screenshots of what it does? Secondly have you built the dist and cleared the cache?

@niravasher
Copy link
Author

This is not doing anything. Yes I built the dist and cleared the cache @harshkhandeparkar

@jywarren
Copy link
Member

jywarren commented Mar 22, 2019 via email

@niravasher
Copy link
Author

niravasher commented Mar 22, 2019

I am not going for resize now. Will do that later. Right now I am moving the image to the right so that it does not get cropped when the gradient is applied. Yes for now it will get cropped from the opposite direction.

@niravasher
Copy link
Author

I made a new js file inside the folder _nomodule. I can now translate the image any number of pixels in any direction and it won't be cut.
Screenshot (50)

The next step is, I am applying the gradient and opening a PR today itself.
After that will work on resizing the canvas @jywarren @harshkhandeparkar

@harshkhandeparkar
Copy link
Member

👍 what is that file called? Can the same func be added to PixelManipulation? Like a function translatePix(x, y) just like others like getNeighboutPixel, extraManipulation, changePixel? Or alternatively, you can require that file in PixelManipulation and let PixelManipulation return the func. If you have already done this then it's ok.

@niravasher
Copy link
Author

I am trying to add it to pixelManipulation

@niravasher
Copy link
Author

Yay! Pixel manipulation is modified, we have a shadow 😄
Screenshot (51)
@harshkhandeparkar

@harshkhandeparkar
Copy link
Member

Wow! Can the shadow be oy added in the top and left sides or anywhere? (I mean can the function oy translate the img in +ve directions or also -ve)?

@niravasher
Copy link
Author

niravasher commented Mar 23, 2019

I can translate the image in any direction and also can add the gradient in any direction. Shadow can be one sided or two sided but can't be three sided or four sided. @harshkhandeparkar Will open a PR soon

@harshkhandeparkar
Copy link
Member

Ok great!

@niravasher
Copy link
Author

niravasher commented Mar 23, 2019

I am stuck here. I have to call changePosition function every time when I press apply button, this is only possible when I keep the function inside draw function. So I removed it from pixelManipulation and took it in Module.js. Here I declared an array called pixelArray. All the channels of all pixels are stored in this array. Now I do pixels.set(x-firstValue, y-secondValue, channel, pixelArray[i]) . This shifts the pixels by firstValue and secondValue. But this is not working, opening up a PR, please help me debug there.
@harshkhandeparkar @jywarren .
#932

@harshkhandeparkar
Copy link
Member

PixelManipulation does run each time you press the apply button. You just put PixelManipulation inside draw.

@jywarren
Copy link
Member

Hi @niravasher can you share a PR? are you using the blur module to generate the shadow?

This is looking good, but I was thinking we really could make a metamodule if we debug the other modules to follow a path like this:

https://sequencer.publiclab.org/examples/#steps=threshold{},blur{},overlay{offset:-4}

See, here, we:

  1. threshold the image to make a black and white version
  2. then we blur the black and white version to make the shadow
  3. then we overlay the original image over the blurry shadow

But a few missing features or bugs are stopping us:

  1. blur does not have a radius Add blur radius #944
  2. overlay seems not to be working
  3. blurring an image with alpha channel seems not to work; we need to blur the alpha channel too, maybe?

See how this might be made to work, though?

I think also that making a canvas-size module which can increase the canvas size, would be a good idea to make this easier.

Thanks for your hard work, @niravasher !

@niravasher niravasher mentioned this issue Jan 14, 2020
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has-pull-request Issues which have a PR open
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants