croptool

Image cropping tool
git clone git://lumidify.org/croptool.git (fast, but not encrypted)
git clone https://lumidify.org/git/croptool.git (encrypted, but very slow)
Log | Files | Refs | README | LICENSE

commit 177d19e34a76175f72efec0315978c0932cf2cb1
parent d3f4eabd38936fae96a96b94801bcb753d42cde1
Author: lumidify <nobody@lumidify.org>
Date:   Sat,  6 Mar 2021 19:31:59 +0100

Allow a different destination filename in croptool_crop

Diffstat:
Mcroptool.c | 14++++++++++----
Mcroptool_crop.1 | 26+++++++++++++++++---------
Mcroptool_crop.c | 14+++++++++++---
3 files changed, 38 insertions(+), 16 deletions(-)

diff --git a/croptool.c b/croptool.c @@ -130,6 +130,7 @@ static struct { Cursor grab; } cursors; +static void usage(void); static void mainloop(void); static void setup(int argc, char *argv[]); static void cleanup(void); @@ -160,6 +161,13 @@ static void key_press(XEvent event); static void queue_update(int x, int y, int w, int h); static int parse_small_positive_int(const char *str, int *value); +static void +usage(void) { + fprintf(stderr, "USAGE: croptool [-mr] [-f format] " + "[-w width] [-c padding] [-p color] [-s color] " + "file ...\n"); +} + int main(int argc, char *argv[]) { char c; @@ -194,9 +202,7 @@ main(int argc, char *argv[]) { } break; default: - fprintf(stderr, "USAGE: croptool [-mr] [-f format] " - "[-w width] [-c padding] [-p color] [-s color] " - "[file ...]\n"); + usage(); exit(1); break; } @@ -205,7 +211,7 @@ main(int argc, char *argv[]) { argc -= optind; argv += optind; if (argc < 1) { - fprintf(stderr, "No file given\n"); + usage(); exit(1); } setup(argc, argv); diff --git a/croptool_crop.1 b/croptool_crop.1 @@ -1,4 +1,4 @@ -.Dd January 2, 2021 +.Dd March 6, 2021 .Dt CROPTOOL_CROP 1 .Os .Sh NAME @@ -6,22 +6,27 @@ .Nd simple image cropping tool .Sh SYNOPSIS .Nm -.Ar WIDTHxHEIGHT+X+Y -.Ar filename +.Ar <width>x<height>+<x>+<y> +.Ar <source filename> +.Op Ar destination filename .Sh DESCRIPTION .Nm crops the given -.Ar filename +.Ar source filename to the dimensions specified, where -.Ar WIDTH +.Ar width and -.Ar HEIGHT +.Ar height are the width and height of the cropping rectangle, and -.Ar X +.Ar x and -.Ar Y +.Ar y specify the top left corner of the cropping rectangle. -This is primarily meant as a companion to +If a +.Ar destination filename +is given, the cropped image is written to this file instead +of modifying the source image in-place. +This program is meant primarily as a companion to .Xr croptool 1 . .Sh EXIT STATUS .Ex -std @@ -30,5 +35,8 @@ This is primarily meant as a companion to .Xr mogrify 1 .Sh AUTHORS .An lumidify Aq Mt nobody@lumidify.org +.Sh CAVEATS +The image format of the cropped image is determined by the format of the +source image, even if the destination file has a different ending. .Sh BUGS At least some versions of Imlib2 seem to have issues with saving gif files. diff --git a/croptool_crop.c b/croptool_crop.c @@ -21,16 +21,24 @@ int main(int argc, char *argv[]) { + char *dst_filename; char *format; char alpha; int w, h, x, y; int orig_w, orig_h; Imlib_Image src, dst; Imlib_Load_Error error; - if (argc != 3) { - fprintf(stderr, "USAGE: croptool_crop WIDTHxHEIGHT+X+Y FILENAME\n"); + if (argc < 3 || argc > 4) { + fprintf(stderr, + "USAGE: croptool_crop <width>x<height>+<x>+<y> " + "<source filename> [destination filename]\n" + ); exit(1); } + if (argc == 4) + dst_filename = argv[3]; + else + dst_filename = argv[2]; /* FIXME: proper error checking for this (don't use sscanf) */ if (sscanf(argv[1], "%dx%d+%d+%d", &w, &h, &x, &y) < 4) { fprintf(stderr, "Invalid cropping rectangle specified.\n"); @@ -65,7 +73,7 @@ main(int argc, char *argv[]) { imlib_blend_image_onto_image(src, 1, x, y, w, h, 0, 0, w, h); imlib_image_set_format(format); - imlib_save_image_with_error_return(argv[2], &error); + imlib_save_image_with_error_return(dst_filename, &error); if (error) { fprintf(stderr, "Unable to save cropped image.\n"); exit(1);