Four ways to crop images in OS X

    Hello.
    I’ll clarify the title right away: slicing meant creating small copies of png and jpg files. That is, what is sometimes required by developers / typesetters / designers. In my particular case - reducing the picture for Retina displays by 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: you open the picture in the editor, reduce it to 50% (insert the desired number), save with the desired name. If the macro is hung up with a hotkey, then the time is spent only on renaming the file and initial loading of the editor. As a result - 30 seconds per file, not for long, but if there are a lot of files, then the loss of time is noticeable.
    I bet that many, very many, have done or have done so for some period of their career. I myself, knowing that all this can be easily automated, still chopped wood with a blunt ax, reassured by the thought that there was simply no time to sharpen it. And finally this time has come.
    Important Information
    The catalyst, by the way, was this comment thread.

    Method # 1: "Everything is already done for us"

    There are quite a multifunctional paid program, as well as a tool in Photoshop since v. 14.1 (thanks to designiac for the link). They do their magic right from 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 still won’t do everything for you. Of course, I would like to hear the opinion of those who used similar tools, maybe I'm wrong, and they really do magic.

    Method # 2: “Automation for Housewives”

    So, we have a set of images in png and jpg formats in the highest resolution of the required, which we or someone else has already cut. We 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 enters the arena ! A piece with great features and easy to use. The functionality we need is done in a few clicks of the mouse, and with the help of this guide , for example, even my mother can handle everything. And the thing is not even that my mother is a fairly advanced user, but 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 1.3 Mb icon with Otto's robot). The application will ask you to select the source files, then the folder where to place the smaller copies, and reduce the selected files by 50%, removing the postfix for retina '@ 2x' in their names. If other types of files fall under 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 percentage reduction, a different naming method), you will have to create a separate application. It is possible that if you snoop on the manuals, everything can be implemented within the framework of one application, but why do complex things with a tool designed for simple ones?
    Using Automator, you can make a full-fledged application, or the so-called. service - a sequence of certain actions that can be integrated into the operating system, which can be called directly from the context menu of the file. Perfect as an addition, if you need to apply the action not to the whole list of files, but pointwise. In addition, a service call can be hung on a hotkey, but for some reason this does not work . The end result, if you are too lazy to do it yourself, is by reference . You need to unzip the archive and copy the file inside it with the workflow extension to your user’s Library / Services folder.
    Automator programs most likely do image processing using the sips tool built into OS X, the final result, when compared pixel by pixel, sometimes differs from the result of a similar reduction in the picture 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 perversions will first of all think about this. Write yourself! There are a lot of advantages here: a convenient graphical interface, fine-tuning of everything you need, confidence that the application will not let you down ... but all this provided that you invest some amount of labor. I overcame myself and decided to invest. It turned out, in my opinion, not bad. Something like this:


    In addition to choosing the source folder and destination folder, you can specify the percentage reduction and a line with a specific syntax (mask), which will be renamed. For example, the mask - @ 2x means that the text @ 2x will be removed from the name , and * + _ copy means that it will be added to the end of the file name (before the extension)_copy .
    I tried to describe all the subtleties of the syntax
    Renaming of reduced copies of the source images takes place using the specified name mask using control characters and value
    characters There are only four Control characters: - (minus), + (plus), * (asterisk) and / (forward slash). Value symbols - 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 character-values ​​until the next control character '+' or '-' or the end of the line will be deleted from the final file name, if they are there of course. Example: - @ 2x will do what it most likely needs to - delete all occurrences of '@ 2x' in the file name.
    The appearance of a plus sign means that the sequence of subsequent value characters until 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 symbol is only the first asterisk, all subsequent ones are perceived as value symbols. If the control asterisk is among the value symbols, then it is considered to be standing before the next symbol '+' or '-'. An asterisk does not affect the sequence with a minus in any way. Examples:
    - @ 2x + foo * + _ copy will delete all occurrences of '@ 2x', add 'foo' in front of the file name and '_copy' after. The following masks will work out similarly:, - @ 2x + f * oo + _copy and + foo * + _ copy- @ 2x
    First all minus masks are executed, then all plus masks.
    The slash escapes the control character following it so that it is considered a value character.

    I implemented image processing inside the application using the same sips, so the output is similar to the programs generated using Automator.
    If you wish, you can also apply this disgrace simply 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 sources for github, if anyone would be interested - write, I will drop them into the 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.

    Also popular now: