[Solved]Reading File Paths from a text File

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
rohitkrishna
Posts: 43
Joined: 2011-10-01T14:34:04-07:00
Authentication code: 8675308

[Solved]Reading File Paths from a text File

Post by rohitkrishna »

Hi every one,

Iam trying to read paths of images from a text file and load them into wands...im getting a status problem...can anyone please help me with it and i want to write all images with a different file name ..im trying something like this...

Code: Select all

int main(int argc,char **argv)
{
	MagickWand    *magick_wand;

	FILE *fp;
	fp = fopen("./filenames.txt", "r");
	char str[200];
	if (argc != 4)
	{
		(void) fprintf(stdout,"Usage: %s image \n",argv[0]);
		exit(0);
	}

	/*
	Read an image.
	*/

	MagickWandGenesis(); // to initialize the magick-wand Environment
	
	magick_wand=NewMagickWand(); // To create the wand to store image

	printf("Loading Image....");
	while(fgets(str,sizeof(str),fp) != NULL)
	{
		status=MagickReadImage(magick_wand,str); // Function to read image into wand
	
		if (status == MagickFalse)
		{
			printf ("status problem");
		}
	
		v.sbimg_wdt=v.sbimg_hgt=atoi(argv[2]);
		v.treshold=atoi(argv[3]);
	
		subimages_pxls(magick_wand,v,argv);
	
		magick_wand=DestroyMagickWand(magick_wand); // To Destroy the image in the wand
		MagickWandTerminus();// To terminate the magick-wand Environment
	}
	return(0);
}
To write the image...m is a loop variable...it is an integer..

Code: Select all

MagickBooleanType status;
		printf("Writing New Image.....");
		status=MagickWriteImages(wand,"res[m].png",MagickTrue);
		if (status == MagickFalse)
		{
			printf ("status problem");
		}
Thanks in advance.
Last edited by rohitkrishna on 2012-05-19T11:20:11-07:00, edited 1 time in total.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Reading File Paths from a text File

Post by anthony »

What is the problem? you are having exactly. What goes wrong?
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
rohitkrishna
Posts: 43
Joined: 2011-10-01T14:34:04-07:00
Authentication code: 8675308

Re: Reading File Paths from a text File

Post by rohitkrishna »

anthony wrote:What is the problem? you are having exactly. What goes wrong?
Im not able to read the image....im tryin to read image path from a text file....and load it in to a wand...but its not loading the image into the wand.. its giving me status problem...im reading the string from the text file in to str and passing it as an argument to the MagicKReadImage()..
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Reading File Paths from a text File

Post by anthony »

Are you permission right. What exception errors are you getting, that will tell you what is going wrong!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
rohitkrishna
Posts: 43
Joined: 2011-10-01T14:34:04-07:00
Authentication code: 8675308

Re: Reading File Paths from a text File

Post by rohitkrishna »

anthony wrote:Are you permission right. What exception errors are you getting, that will tell you what is going wrong!
Its just saying status problem..nothing more...and when im writing image..its not writing just one image..its reproducing multiple images.....each time
rohitkrishna
Posts: 43
Joined: 2011-10-01T14:34:04-07:00
Authentication code: 8675308

Re: Reading File Paths from a text File

Post by rohitkrishna »

rohitkrishna wrote:
anthony wrote:Are you permission right. What exception errors are you getting, that will tell you what is going wrong!
Its just saying status problem..nothing more...and when im writing image..its not writing just one image..its reproducing multiple images.....each time
Thank you for helpin...
i figured out how to read the images...but im stuck at writing the output to a different image each time....its wiriting the results to same file over and over each time.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Reading File Paths from a text File

Post by anthony »

From what I can tell @ syntax will not work with any filename containing a directory separator. That is it is restricted to the current directory, and the filename needs to reflect this.

This may be a security measure, though I do not have any definitive answer on this, nor have to reviewed the code. Though I will be at some point as part of my part in the ongoing IMv7 Redevelopment.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
rohitkrishna
Posts: 43
Joined: 2011-10-01T14:34:04-07:00
Authentication code: 8675308

Re: Reading File Paths from a text File

Post by rohitkrishna »

anthony wrote:From what I can tell @ syntax will not work with any filename containing a directory separator. That is it is restricted to the current directory, and the filename needs to reflect this.

This may be a security measure, though I do not have any definitive answer on this, nor have to reviewed the code. Though I will be at some point as part of my part in the ongoing IMv7 Redevelopment.
Thanks anthony for your suggestions...i have finally figured how to read and write different images....by reading filepaths from a file.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Reading File Paths from a text File

Post by anthony »

Is that file in the current directory?
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
rohitkrishna
Posts: 43
Joined: 2011-10-01T14:34:04-07:00
Authentication code: 8675308

Re: Reading File Paths from a text File

Post by rohitkrishna »

anthony wrote:Is that file in the current directory?
NO they are in differnet directory...i mentioned paths of images in the text file..
Post Reply