|
Server : LiteSpeed System : Linux srv104790275 5.15.0-161-generic #171-Ubuntu SMP Sat Oct 11 08:17:01 UTC 2025 x86_64 User : dewac4139 ( 1077) PHP Version : 8.0.30 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, Directory : /proc/self/root/usr/share/doc/libexif-dev/examples/ |
Upload File : |
/*
* libexif example program to extract an EXIF thumbnail from an image
* and save it into a new file.
*
* Placed into the public domain by Dan Fandrich
*/
#include <stdio.h>
#include <libexif/exif-loader.h>
int main(int argc, char **argv)
{
int rc = 1;
ExifLoader *l;
if (argc < 2) {
printf("Usage: %s image.jpg\n", argv[0]);
printf("Extracts a thumbnail from the given EXIF image.\n");
return rc;
}
/* Create an ExifLoader object to manage the EXIF loading process */
l = exif_loader_new();
if (l) {
ExifData *ed;
/* Load the EXIF data from the image file */
exif_loader_write_file(l, argv[1]);
/* Get a pointer to the EXIF data */
ed = exif_loader_get_data(l);
/* The loader is no longer needed--free it */
exif_loader_unref(l);
l = NULL;
if (ed) {
/* Make sure the image had a thumbnail before trying to write it */
if (ed->data && ed->size) {
FILE *thumb;
char thumb_name[1024];
/* Try to create a unique name for the thumbnail file */
snprintf(thumb_name, sizeof(thumb_name),
"%s_thumb.jpg", argv[1]);
thumb = fopen(thumb_name, "wb");
if (thumb) {
/* Write the thumbnail image to the file */
fwrite(ed->data, 1, ed->size, thumb);
fclose(thumb);
printf("Wrote thumbnail to %s\n", thumb_name);
rc = 0;
} else {
printf("Could not create file %s\n", thumb_name);
rc = 2;
}
} else {
printf("No EXIF thumbnail in file %s\n", argv[1]);
rc = 1;
}
/* Free the EXIF data */
exif_data_unref(ed);
}
}
return rc;
}