Hello.
Immediately clarify the title: under the cutting meant the creation of reduced copies of png and jpg files. That is, what is sometimes required by developers / layout designers / designers. In my particular case - reducing the picture for Retina displays in half under normal screens.
Method # 0, canonical
That is, Photoshop or some other image editor with the direct participation of the user. The sequence of actions is as follows: open the picture in the editor, reduce it to 50% (insert the required number), save it with the required name. If a reduction of the image is hanged by a macro on a hotkey, then the time is spent only on renaming the file and initial loading the editor. As a result - 30 seconds per file, not for long, but if there are many files, then the loss of time is noticeable.
I can argue that many, very many, and do or did during a certain period of his career. I myself, knowing that all this can be easily automated, still chopped wood with a blunt ax, calming down with the thought that there is simply no time to grind it. Finally, this time has come.
Method # 1: "Everything is already done for us"
There are quite multifunctional paid programs, as well as a tool in
Photoshop since v. 14.1 (thanks to
designiac for the link). They spin their magic right with the psd file, eliminating some routine operations. All this, of course, is cool, but firstly, for money (they still use licensed software!), And secondly, they will not do everything for you anyway. Of course, I would like to hear the opinion of those who used such tools, maybe I'm wrong, and they really do magic.
Method # 2: “Automation for Housewives”
So, we have a set of images in the png and jpg formats in the largest resolution of those that we or someone else has already cut. You need to create copies of these images, proportionally reduced by a certain number of times, and also rename them as we need. And of course,
Automator is entering the arena! Stuck with great features and easy to use. The functionality we need is done in a few mouse clicks, and with the help of
this guide , for example, even my mom can handle everything. And it's not even that my mom is a fairly advanced user, but the fact that it is really very simple.
Therefore, I will not describe the creation process here, if someone is suddenly interested in the result -
please (the size of such a small program is so large primarily because of the icon with the Otto robot with a volume of 1.3 Mb). The application will ask you to select the source files, then the folder where to place the reduced copies, and reduce the selected files by 50%, removing the postfix for the retina '@ 2x' in their names. If other types of files get caught up in the hot hand, they will also be copied and renamed, if possible. The disadvantage of this approach is that for each specific scenario (a different reduction percentage, a different naming method), you will have to do a separate application. It is possible that if you tinker over manuals, everything can be implemented within the framework of a single application, but why make complex things a tool designed for simple ones?
With the help of Automator, you can make a full-fledged application, and so on. service - a sequence of certain actions integrated into the operating system, which can be called directly from the context menu of a file. Perfect as an addition if you need to apply an action not to the whole list of files, but to a point. In addition, the service call can be hanged on a hotkey, although
for some reason it does not work . The end result, if you are too lazy to do it yourself, is
by reference . You need to unpack the archive and copy the file with the workflow extension to its user’s Library / Services folder.
Image processing from Automator is most likely done using the
sips tool built into OS X, the end result, when compared pixel-by-pixel, sometimes differs from the result of a similar reduction in Photoshop, but the differences are minimal and the images look good anyway.
Method # 3, for true connoisseurs
Of course, every conscious citizen who knows a lot about perversion will think about this first of all. Write yourself! There are a lot of advantages: a user-friendly graphical interface, tweaking everything you need, confidence that the application will not let you down ... but this is all provided that you invest some amount of work. I overcame myself and decided to invest. It turned out, in my opinion, not bad. Something like this:

')
In addition to selecting the source folder and the destination folder, you can specify the percentage of reduction and the line with a certain syntax (mask), which will be renamed. For example, the mask
- @ 2x means that the text will be removed from the name
@ 2x , and
* + _ copy means that
_copy will be added to the end of the file name (before the extension).
I tried to describe all the subtleties of the syntaxRenaming of the reduced copies of the original images occurs according to the specified name mask using control characters and character-values
There are only four control characters: - (minus), + (plus), * (asterisk) and / (forward slash). Symbols-values - all other symbols to your taste.
Any value characters before the first control character are ignored.
The appearance of a minus means that the sequence of subsequent characters to the next control character '+' or '-' or the end of the line will be removed from the final file name if they are there of course. Example: - @ 2x will do what is most likely and necessary - will remove all occurrences of '@ 2x' in the file name.
The appearance of a plus means that a sequence of subsequent characters-values up to the next control character '+' or '-' or the end of the line will be added to the end or beginning of the final file name.
An asterisk means that all sequences with a plus before it are added to the beginning of the name, and after it to the end. The control character is only the first asterisk, all following are perceived as character-values. If the control asterisk is among character-values, then it is considered to be in front of the next '+' or '-' character. The asterisk does not affect the sequence with minus. Examples:
- @ 2x + foo * + _ copy will remove all occurrences of '@ 2x', add 'foo' before the file name and '_copy' after. Similarly, the following masks will work: Yutsuk-@ 2x + foo * + _ copy , - @ 2x + f * oo + _copy and + foo * + _ copy- @ 2x
Initially, all minus masks are executed, then all plus masks.
The slash escapes the following control character to be considered a value character.
I implemented the image processing inside the application using all the same sips, so the output is the same as the programs generated using Automator.
If you wish, you can also apply this disgrace just for group renaming, choosing the same folder as the receiver and as the source, and setting the reduction percentage to 100.
The link to the compiled application is
here (tested on OS X 10.8.5), for some unobvious reasons, I don’t upload the github source code, if anyone is interested, write, drop it to you with an archive.
Thank you for your attention, let automation be with us!
PS Please note that the post does not imply that these four methods are the only ones.