📜 ⬆️ ⬇️

Moderated Brush Collection for GIMP

Hello, I want to tell you today about one non-commercial project.

For those who are not in the subject: there is an open-source image editor called Gimp . To tell about it, a site was created for ordinary people, on which lessons and descriptions of this editor were posted. But it will not be about the site itself.

The editor uses its own brush format. The thought came about creating a catalog in which one could search for the necessary brushes and quickly download them.
')
What are the advantages of the project for users:

Organization preview brushes


Actually, what is this preview itself - just a sketch of the appearance of the brush itself and a trial stroke by it in different colors.

image

To begin development, the documentation for the brushes used in the GIMP was found. As it turned out, the Gimp brush in the GBR format is quite simple - it consists of a header describing the brush itself and the bitmap of the stored image.

The main problem that faced was getting the correct image from the bitmap. At first there was an idea to make unpack for the whole part of the file containing bitmap, but this led to the fact that on full-color brushes with a size of 500x500 points the memory simply ended (the interpreter was allocated up to 256 MB of RAM). Apparently, this is somehow related to the memory model when organizing PHP arrays, but I didn’t dig in, but decided to change the algorithm. Having studied the documentation a little, I came to the conclusion that you can calmly, albeit slowly, read the file in small portions using the infamous file_get_contents (), and then work with unpack ().

Brush Selection Interface


But besides the generator of strokes and sketches of the brush itself, an interface was created that allows to select brushes according to the features of interest.

image

Turning on the filter (1) and selecting one or more marks for the brush (2) will show you the brushes that meet your requirements (5). Brushes are shown in the form of small strokes, so that you can immediately determine how the brush will behave when drawing. Numbers is the size of the brush in pixels.

When turning on tags (2), the search parameters can be specified by active tags (4). The gray mark (3) is inactive, there are no brushes with such parameters.


Naturally, it was decided that it should be fast and convenient, but this is precisely what the concept of Ajax requests to the server contributed to.

As you know, the slowest when working on a network is to contact the server and wait for a response from it. Based on this paradigm, it was decided to do a maximum of work with a minimum of requests, therefore, for any sample, 1 request was made that received all the necessary information about the entire set of brushes in the JSON-structure format.

If you look at the service, you will see that by clicking on the thumbnail of the brush, a window opens in which there is all the necessary information on the brush already received from the server. But after opening the window, an asynchronous request is launched, which calls the server handler to count the brush scans. In addition to the information in this window, a flash insert is implemented that allows you to test the brush “without departing from the cash register”.

image

Performance without JS


It would seem, Ajax-Ajax and all is well. But good is not for everyone. There are some comrades who disable JS, as well as the search engines for which we made a regular web page about each brush. On this page there is a brush and its full detailed description. In addition to the pages with brushes, pages of selections with tags were made. It was implemented that if JS is enabled, then from these pages you can use the samples as usual.

You can view and touch the interface here: www.progimp.ru/downloads/brushes

Source: https://habr.com/ru/post/107289/


All Articles