Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
GGR from Image
#21
Hello guys!

I thought it best not to open a new topic since in part the question is somewhat the same.

I've been familiar with creating gradients from part of images for some time now. Either via Sample Gradient Along Path or via Gradient from Image... (plugins/script found in the gradient window).

However, I've been trying to create a gradient from a small image (27x12 px) for hours without being able to create the correct gradient.

I tried with the path both the exact width of the layer, and with a path a few pixels longer.

I made several attempts with both Sample Gradient Along Path and Gradient from Image.

I tried the tip from rich2005 about the option of G'MIC - Gradient from Line, but I believe that this filter is buggy.
As in meetdilip post #10, the preview displays a similar error. However if I uncheck the "Preview Gradient" option the error message disappears and it is possible to interact with the filter by adjusting the line to collect the gradient.

But even though, after adjusting the filter I manage to create an image identical to my original image, the .ggr is not created.

I searched for . ggr that was supposed to be created, either by refreshing the gradients window several times, or by checking the Gimp's gradient folders, and was not found.

I restarted Gimp, I think I read meeddilip say that this made the . ggr appear for him. It didn't work here.

Pixlab suggested updating the G'MIC, but that's what I happened to do a few days ago. I have version 3.1.6 at the moment.

In short:

How to get a gradient that exactly reproduces the gradient of the image below (Top - Original - the desired one).
   
After the top (original) gradient, here are 3 examples of other gradients that I have gotten in my attempts.

Thank you very much in advance!
                               .....
Samj PortableGimp 2.10.28 - Win-10 /64.
Reply
#22
Because it's only 27 pixels =27 columns, and you got problem with script/G'MIC/etc... I would create it manually, just not bothering anymore, and picking color on your original with left and right end point, and all in the middle
Reply
#23
The RobA sample along path certainly has problems picking up that extreme right-side white-black strips, so using the gmic plugin.

The 27 pix width is a problem for gmic, it creates an error, solution scale the image up say 500% using interpolation None to preserve the hard edges.

   

Now we can use the gmic filter Gradient from line
I would enter start and finish (0, 100) rather than eye-balling the points
Sampling = 27, for the 27 bands, length = 0 to preserve the hard edges
Give it a name, OK it, and it puts the .ggr straight into the gradients folder. Only problem I can see is your portable Gimp and where is the gradients folder ?

   

Back into a tiny canvas, not as easy as you might think, needs a steady hand  Wink

   

Attached as an example (zipped) 01.ggr :


Attached Files
.zip   01.ggr.zip (Size: 987 bytes / Downloads: 194)
Reply
#24
Try this:
  • Open the palette editor (in the Palettes list click the "Create new palette" button
  • Color sample each band in turn, then clikc the + button in the palette editor to add it (the ruler is my screen ruler app that I used to keep track of where I was)
   
  • Give a name to your palette. It should appear in the Palettes list
  • Right click that palette, and Color to gradient
  • In the Gradients list, you should now have a Gradient with the name of your palette
  • Create a rectangular selection on part of your image
  • Set the active gradient to the one sampled from your palette
  • Start the Blend tool and drag the gradient across your image
  • Adjust the stops (more or less in the middle of their bands) so that the bottom is aligned to the top (yes, I probably missed a color on the right)
   
  • At the top of the Gradients list, right click the Custom gradient (which is the one you creating on the fly), and duplicate and rename it
Reply
#25
Just a mention of SVG gradients. Gimp can use this format. I thought I had a linux script to generate one from an image but alas not.

This one made by hand, I grouped the colour bands to show the hard edges, usually the stops blend from colour-to-colour. All in text so easy to edit. 

Attached the same example as before: It is not a image, put the file 27lines.svg in your gradients folder.


Attached Files
.svg   27lines.svg (Size: 3.18 KB / Downloads: 85)
Reply
#26
(10-06-2022, 04:19 AM)PixLab Wrote: Because it's only 27 pixels =27 columns, and you got problem with script/G'MIC/etc... I would create it manually, just not bothering anymore, and picking color on your original with left and right end point, and all in the middle

Ehhh... it's embarrassing to say this, but I don't know how to edit/create gradients with the gradient editor. Last week I even tried, but after frustrated attempts I gave up.

(10-06-2022, 08:12 AM)rich2005 Wrote: The RobA sample along path certainly has problems picking up that extreme right-side white-black strips, so using the gmic plugin.

The 27 pix width is a problem for gmic, it creates an error, solution scale the image up say 500% using interpolation None to preserve the hard edges.



Now we can use the gmic filter Gradient from line
I would enter start and finish (0, 100) rather than eye-balling the points
Sampling = 27, for the 27 bands, length = 0 to preserve the hard edges
Give it a name, OK it, and it puts the .ggr straight into the gradients folder. Only problem I can see is your portable Gimp and where is the gradients folder ?



Back into a tiny canvas, not as easy as you might think, needs a steady hand  Wink



Attached as an example (zipped) 01.ggr :

Yesterday, when I tried Gradient from Line (G'MIC), even with the error that appears in the preview window, after unchecking the "Preview gradient" option, I managed to generate an image with a very good, even acceptable gradient. But I was unable to get the .ggr from that filter.

My gradients folder are in default locations (for Samj's portable), I think. 
   

rich2005, thanks for the 27lines.svg and 01.ggr.zip!

(10-06-2022, 08:22 AM)Ofnuts Wrote: Try this:
  • Open the palette editor (in the Palettes list click the "Create new palette" button
  • Color sample each band in turn, then clikc the + button in the palette editor to add it (the ruler is my screen ruler app that I used to keep track of where I was)

  • Give a name to your palette. It should appear in the Palettes list
  • Right click that palette, and Color to gradient
  • In the Gradients list, you should now have a Gradient with the name of your palette
  • Create a rectangular selection on part of your image
  • Set the active gradient to the one sampled from your palette
  • Start the Blend tool and drag the gradient across your image
  • Adjust the stops (more or less in the middle of their bands) so that the bottom is aligned to the top (yes, I probably missed a color on the right)

  • At the top of the Gradients list, right click the Custom gradient (which is the one you creating on the fly), and duplicate and rename it

Wow that was fantastic!
I thought it would be complicated, but I managed to follow the steps of this mini-tutorial. The part of adjusting the stops was a little more complex but it all worked out!

After reviewing the result, I think that the lighting that was on the monitor at the time of editing may have prevented me from finding a better fit (I didn't notice it at the time). But I was satisfied with the result!

I used the original layer on top with a mask revealing only the top half. Underneath I edited the new gradient based on the top layer.
   

(10-06-2022, 02:17 PM)rich2005 Wrote: Just a mention of SVG gradients. Gimp can use this format. I thought I had a linux script to generate one from an image but alas not.

This one made by hand, I grouped the colour bands to show the hard edges, usually the stops blend from colour-to-colour. All in text so easy to edit. 

Attached the same example as before: It is not a image, put the file 27lines.svg in your gradients folder.

Since you brought up the subject of SVG gradients, it reminded me that a little over 1 year ago I tried to play around with it. But I had some kind of difficulty (I don't remember exactly what the difficulty was) so I put it aside and ended up never touching it again.

So after your comment and having downloaded your attachment (27lines.svg) I tried again to understand myself with this resource (SVG gradients with Gimp), but without success.

I think I found the plugin to create this kind of gradient.
So I decided to venture out and even without knowing for sure how to use the plugin I gave it a try.

A strange error appears:

I checked, and that folder and path exist (see screenshot below)
   
But... looking more closely, he mentions Drive D:/Gimp21021/... I think this must have been when I was using version 2.10.21 (and even then the D: drive with Gimp was only used on the LapTop and not on PC)

I don't know why it's tied to this path nor where to try to edit to fix it.


PixLab, rich2005 and Ofnuts,

I really appreciate the help everyone has given me. Thank you very much!
                               .....
Samj PortableGimp 2.10.28 - Win-10 /64.
Reply
#27
Lightbulb 
(10-06-2022, 07:45 PM)Krikor Wrote: A strange error appears:

I checked, and that folder and path exist (see screenshot below)

But... looking more closely, he mentions Drive D:/Gimp21021/... I think this must have been when I was using version 2.10.21 (and even then the D: drive with Gimp was only used on the LapTop and not on PC)

I don't know why it's tied to this path nor where to try to edit to fix it.


PixLab, rich2005 and Ofnuts,

I really appreciate the help everyone has given me. Thank you very much!


I managed to get the plugin to create .svg gradients!  Big Grin

I groped in the dark for a solution.

I found that I still have a copy of version 2.10.21 on one of my usb flash drives.

I Googled and found some posts from 2016 on the subject, but not very enlightening.

Finally I discovered that the location of the folder containing the gradients is within the plugin itself and not through an external file (a .ini for example).

That is, this plugin only worked exclusively on one of my flash drives.  Dodgy

Even so, it took me a while to realize that the direction of the slashes ( \ or /) was another factor by itself enough to keep generating an error when I had already changed the location of the directory and the gradient folder.

Now it's time for the fun!
                               .....
Samj PortableGimp 2.10.28 - Win-10 /64.
Reply
#28
Ok, just for that svg-gradients plugin, finally found it in my archive, it is one of Tin's plugins but for Gimp 2.8

lines 37-39 are set up for a regular Gimp and you can 'hard encode' the path to your version of Gimp

Code:
#where gradient folder is located, the ~ will be expanded by calling os.path.expanduser() function later
#gradient_folder = "~/.gimp-2.8/gradients/";
gradient_folder = os.path.join("~",".gimp-2.8","gradients","") #as suggested by dinasset to not hardcode slashes.

To make it more portable comment out line 39 and add a line as;

Code:
#where gradient folder is located, the ~ will be expanded by calling os.path.expanduser() function later
#gradient_folder = "~/.gimp-2.8/gradients/";
#gradient_folder = os.path.join("~",".gimp-2.8","gradients","") #as suggested by dinasset to not hardcode slashes.

gradient_folder = os.path.join(gimp.directory, "gradients", "")

That is working here, linux Gimp 2.10.32 also in a Win10 VM both for regular Gimp and Samj portable.

It is not bad for making a simple gradient but for those hard edges, some hand editing is needed. Not a bad way of getting an initial SVG gradient template.

If you do not fancy editing the plugin, the edited version attached.


Attached Files
.zip   svg-gradients.zip (Size: 3.31 KB / Downloads: 101)
Reply
#29
(10-07-2022, 08:50 AM)rich2005 Wrote: To make it more portable comment out line 39 and add a line as;

Code:
gradient_folder = os.path.join(gimp.directory, "gradients", "")

That is working here, linux Gimp 2.10.32 also in a Win10 VM both for regular Gimp and Samj portable.

Definitely the way... works for any OS, Gimp version, and GIMP2_DIRECTORYenvironment setting.

For the nitpicking crowd, the final ,'' is not necessary, it is used to add a final /, but this thing should be done else where, for instance

Code:
newfilename = gradient_folder + gradient_name + ".svg"

should be

Code:
newfilename = os.path.join(gradient_folder,gradient_name + ".svg")

(lines 67, 107 and 175) and the various calls to os.path.expanduser() are not necessary because the directory returned by gimp.directory() is already fully resolved. In fact one wonders why this was not done once for all when initializing the gradient_folder variable, and the DRY principle demands that you would have some gradientFileFromName() function that would handle all this in a single place.
Reply
#30
@Ofnuts

I knew you would have a better solution, forgive my amateur attempts. Wink

Now the most important biz, Friday afternoon, off to see some friends for a beer (or two)
Reply


Forum Jump: