ImageGear for C and C++ on Linux v20.0 - Updated
Convert an Image
User Guide > Getting Started > Samples > Convert an Image

The igconsole sample program demonstrates how to load an image in one format and convert it to another format.

Usage: igconsole [options]
where [Options] may include any of the following:
-i[page number] <input file>
-o[page number] <output file>
-e <Component name>
-f <output format ID>
-p <list all possible output formats ID's>
-v <display version numbers>

This topic provides information about the command-line parameters of this program and the corresponding ImageGear API calls which implement the requested functionality.

  1. Load the specified page from the multi-page image:

    -i[nIPageNumber] < IFileName >

    The sample uses the IG_fltr_load_file() function to load the specified page from the multi-page image and associate it with the hIGear handle:

    nErrCount=IG_fltr_load_file(IFileName, nIPageNumber, &hIGear);

  2. Set the output format value using the command-line parameters. Save the already-loaded hIGear image into OFileName as nOPageNumber-th page:

    
    -f nFormat
    -o[nOPageNumber] OFileName
    

    The sample uses the IG_fltr_save_file() function to save the already-loaded hIGear image in the format of the nFormat parameter value:

    nErrCount=IG_fltr_save_file(hIGear, OFileName, nFormat, nOPageNumber, FALSE);

    The nFormat value is an integer constant taken from ImageGear’s master include file accucnst.h.

  3. Get a list of all possible output formats:

    -p

    This command returns a list of all currently available output formats by:

    <format_id>:<Format_name>.<Compression_name>

    The contents of the list depend upon the component that is attached (refer to Component Manager API). For example, if the LZW component is loaded, then the GIF/LZW format is available for use and will appear in the list.

    The sample uses the IG_fltr_savelist_get function to obtain the list of output formats, and then calls the IG_fltr_info_get function in a loop to obtain information on each output format.

    Please see the igconsole.c source file for the code that implements this feature.

  4. Return the list of all possible output formats for a given image:

    -i[nIPageNumber] < IFileName >

    This loads the nIPageNumber page of an IFileName file and then returns a list of all available output formats to which the loaded image can be saved.

    The sample uses the IG_fltr_savelist_get function to obtain the list of output formats, and then calls the IG_fltr_info_get function in a loop to obtain information on each output format.

    Please see the igconsole.c source file for the code that implements this feature.

  5. Attach a component:

    -e component_filename

    The sample uses IG_comm_comp_attach to attach a component:

    nErrCount=IG_comm_comp_attach(component_filename);

    The following example loads the second page from a mydocument.pdf document and saves it to a JPEG file:

    igconsole -e libIGPDF.so -i2 mydocument.pdf -f 393237 -o tiff6_p2.jpg

    The following example converts the first page of the input document to BMP format:

    
    char *argv[]
    HIGEAR hIGear;/* ImageGear image handle */
    AT_ERRCOUNTnErrCount;/* Number of errors that occurred */
    ...
    /* Load the image in argv[1] */
    nErrCount = IG_fltr_load_file(argv[1], 1, &hIGear);
    if (nErrCount)
    {
        ErrorReport(nErrCount);
        exit(1);
    }
    /* Save the image as a BMP in argv[2] */
    nErrCount = IG_fltr_save_file(hIGear, argv[2], IG_FORMAT_BMP, 0,
    FALSE );
    if (nErrCount)
    {
        ErrorReport(nErrCount);
        exit(1);
    }
    ...
    

Is this page helpful?
Yes No
Thanks for your feedback.