int main(int argc, char const *argv[]) { char input[] = "../example.jpg"; char output[] = "transform.jpg"; Epeg_Image *img; if (!(img = epeg_file_open(input))) { printf("Could not open image %s\n", input); exit(1); } epeg_transform_set(img, EPEG_TRANSFORM_ROT_270); epeg_file_output_set(img, output); if (epeg_transform(img) != 0) { printf("Transform failed\n"); exit(2); } epeg_close(img); return 0; }
JPEG_THUMB_STATUS jpeg_thumb_file_(char* src,char* dst,JPEG_THUMB_CONFIG* config ){ Epeg_Image * image; int ch; image = epeg_file_open(src); if (!image) { return JPEG_THUMB_STATUS_SRC_FILE_NOT_EXIST; } epeg_decode_size_set(image, config->width, config->height); epeg_quality_set (image, config->quality); epeg_file_output_set(image, dst); epeg_encode(image); epeg_close(image); return JPEG_THUMB_STATUS_OK; }
JPEG_THUMB_STATUS jpeg_thumb_file(const char* src,const char* dst,int width,int height, int quality ){ Epeg_Image * image; int ch; image = epeg_file_open(src); if (!image) { return JPEG_THUMB_STATUS_SRC_FILE_NOT_EXIST; } epeg_decode_size_set(image, width, height); epeg_quality_set (image, quality); epeg_file_output_set(image, dst); epeg_encode(image); epeg_close(image); return JPEG_THUMB_STATUS_OK; }
/* * call-seq: * write(file_path) * * Writes the image to +file_path+ and closes the image stream. * Please note that you can't do any further operations on the image * after using this method. */ static VALUE rb_epeg_image_write(VALUE self, VALUE file_path) { Check_Type(file_path, T_STRING); if(rb_iv_get(self, "epeg_file_closed") != Qfalse) { rb_raise(rb_eRuntimeError, "Error: closed file"); } Epeg_Image *image; Data_Get_Struct(self, Epeg_Image, image); epeg_file_output_set(image, StringValueCStr(file_path)); rb_epeg_image_encode_or_trim(self, image); rb_epeg_image_close(self); return Qnil; }
/* main function: */ int main(int argc, char **argv) { Epeg_Image *im; if (argc != 3) { printf("Usage: %s input.jpg thumb.jpg\n", argv[0]); exit(0); } im = epeg_file_open(argv[1]); if (!im) { printf("cannot open %s\n", argv[1]); exit(-1); } else { /* (the "else" is new, but it should work the same) */ const char *com; Epeg_Thumbnail_Info info; int w, h; com = epeg_comment_get(im); if (com) { printf("Comment: %s\n", com); } epeg_thumbnail_comments_get(im, &info); if (info.mimetype) { printf("Thumb Mimetype: %s\n", info.mimetype); if (info.uri) { printf("Thumb URI: %s\n", info.uri); } printf("Thumb Mtime: %llu\n", info.mtime); printf("Thumb Width: %i\n", info.w); printf("Thumb Height: %i\n", info.h); } epeg_size_get(im, &w, &h); printf("Image size: %ix%i\n", w, h); } epeg_decode_size_set(im, 128, 96); #if 0 if (0) { unsigned int *pixels; # if 0 epeg_decode_colorspace_set(im, EPEG_ARGB32); # endif /* 0 */ pixels = epeg_pixels_get(im, 0, 0, 128, 96); if (pixels) { int x, y; unsigned int *p; # if defined(DEBUG) && DEBUG printf("Image pixels:\n"); # endif /* DEBUG */ p = pixels; for ((y = 0); (y < 96); y++) { for ((x = 0); (x < 128); x++) { # if defined(DEBUG) && DEBUG printf("%08x ", p[0]); # endif /* DEBUG */ p++; } # if defined(DEBUG) && DEBUG printf("\n"); # endif /* DEBUG */ } epeg_pixels_free(im, pixels); } } #endif /* 0 */ epeg_quality_set(im, 80); epeg_thumbnail_comments_enable(im, 1); epeg_comment_set(im, "Smelly pants!"); epeg_file_output_set(im, argv[2]); epeg_encode(im); epeg_close(im); return 0; }
int main(int argc, char **argv) { Epeg_Image *im; int c; int option_index = 0; char *input_file = NULL, *output_file = NULL; char *p; while ((c = getopt_long(argc, argv, "w:h:vc:m:", long_options, &option_index)) != -1) { switch (c) { case 0: usage(argv[0]); break; case 'v': verbose_flag = 1; break; case 'w': thumb_width = strtol(optarg, NULL, 10); if (thumb_width == 0) { fprintf(stderr, "setting thumb_width to a default minimum of 64\n"); thumb_width = 64; } else { // If optarg="NUMBER%" store -NUMBER (see below) if ((p = strstr(optarg, "%"))) thumb_width = -thumb_width; } if (verbose_flag) printf("thumb_width = %d\n", thumb_width); break; case 'h': thumb_height = strtol(optarg, NULL, 10); if (thumb_height == 0) { fprintf(stderr, "setting thumb_height to a default minimum of 64\n"); thumb_height = 64; } else { // If optarg="NUMBER%" store -NUMBER (see below) if ((p = strstr(optarg, "%"))) thumb_height = -thumb_height; } if (verbose_flag) printf("thumb_height = %d\n", thumb_height); break; case 'm': max_dimension = strtol(optarg, NULL, 10); if (verbose_flag) printf("max_dimension = %d\n", max_dimension); break; case 'c': thumb_comment = strdup(optarg); if (verbose_flag) printf("thumb_comment = %s\n", thumb_comment); break; case '?': usage(argv[0]); break; default: abort(); } } if (optind < argc) { if (optind < (argc-1)) { input_file = argv[optind++]; if (verbose_flag) printf("input_file = %s\n", input_file); output_file = argv[optind]; if (verbose_flag) printf("output_file = %s\n", output_file); } else { usage(argv[0]); } } if (!input_file || !output_file) usage(argv[0]); if (!thumb_comment) thumb_comment = "Smelly pants!"; im = epeg_file_open(input_file); if (!im) { fprintf(stderr, "%s: cannot open %s\n", argv[0], input_file); exit(-1); } { const char *com; Epeg_Thumbnail_Info info; int w, h; com = epeg_comment_get(im); if (verbose_flag) if (com) printf("Comment: %s\n", com); epeg_thumbnail_comments_get(im, &info); if (info.mimetype) { if (verbose_flag) printf("Thumb Mimetype: %s\n", info.mimetype); if (verbose_flag) if (info.uri) printf("Thumb URI: %s\n", info.uri); if (verbose_flag) printf("Thumb Mtime: %llu\n", info.mtime); if (verbose_flag) printf("Thumb Width: %i\n", info.w); if (verbose_flag) printf("Thumb Height: %i\n", info.h); } epeg_size_get(im, &w, &h); if (verbose_flag) printf("Image size: %ix%i\n", w, h); if (thumb_width < 0) { // This means we want %thumb_width of w thumb_width = w * (-thumb_width) / 100; } if (thumb_height < 0) { // This means we want %thumb_height of h thumb_height = h * (-thumb_height) / 100; } if (max_dimension > 0) { if (w > h) { thumb_width = max_dimension; thumb_height = max_dimension * h / w; } else { thumb_height = max_dimension; thumb_width = max_dimension * w / h; } } } if (verbose_flag) printf("Thumb size: %dx%d\n", thumb_width, thumb_height); epeg_decode_size_set(im, thumb_width, thumb_height); epeg_quality_set (im, 80); epeg_thumbnail_comments_enable (im, 1); epeg_comment_set (im, thumb_comment); epeg_file_output_set (im, output_file); epeg_encode (im); epeg_close (im); return 0; }