read text from csv file using php and create image

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?".
Locked
dav22
Posts: 29
Joined: 2020-02-05T09:22:25-07:00
Authentication code: 1152

read text from csv file using php and create image

Post by dav22 »

running ImageMagick-7.0.9-Q16, on windows 7 64 bit

I was searching through this forum for variation of image creation using data on csv file, I found https://www.imagemagick.org/discourse-s ... hp?t=15279 that Bonzo provided a php script, it can read text from a pipe Delimited csv file and make image out of it for each data on cell.
I am interested in that php script, I don't know about php, but managed to have local host php server and run it on my machine local host,

but it does not work as it should, there is no php error, but no image will be created.

since the post is couple years old, and I run imagemagick ver 7.0.9, I thought maybe that is the reason, so maybe someone or Bonzo can help on this.
on the script I change the covert to magick and put my csv file name there,
I made a test csv file with 10 rows of text, having only one column and is | separated.
when I run the php here is what it looks on browser:
Image
I wonder if anyone can help on this.
this is the php script:

Code: Select all

<?php
// http://php.net/manual/en/function.fgetcsv.php
$row = 1;
if (($handle = fopen("test.csv", "r")) !== FALSE) {
    while (($data = fgetcsv($handle, 1000, "|")) !== FALSE) {
        $num = count($data);
		$text = "";
        $row++;
        for ($c=0; $c < $num; $c++) {
		$text .= $data[$c];
		}
		exec("magick -size 400x100 xc:lightblue -fill black -pointsize 20 -gravity center -annotate +0+0 \"$text\" card$text.jpg");
        echo "<br><img src=\"card$text.jpg\"><br />\n";      
    }
    fclose($handle);
}
?>
Edit: I don't care much about name the file after text inside it,
thanks

snibgo
Posts: 13034
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: read text from csv file using php and create image

Post by snibgo »

What help do you need?

I suggest you paste a link to your CSV file and one or more of the created JPGs.
snibgo's IM pages: im.snibgo.com

dav22
Posts: 29
Joined: 2020-02-05T09:22:25-07:00
Authentication code: 1152

Re: read text from csv file using php and create image

Post by dav22 »

Thanks for the reply;
I just want to make the script work for me,
read text from rows on csv file one by one, and create one image from each row of text, and of course name the image something, that is what I think the script should do.

as I mentioned there is no image created,
the only things I noticed was the broken link image from the browser when I run the script,
I have posted the image above.
nothing created in the folder where the php script and csv file are.
here is the link to csv file.
https://www.dropbox.com/s/26isetgyz5r3mhm/test.csv?dl=0

Thanks

snibgo
Posts: 13034
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: read text from csv file using php and create image

Post by snibgo »

If your magick command didn't create any output image, then it failed. I suggest you trap any text it sends to stderr, an error message, and echo that.

You should also try running it from the command line.
snibgo's IM pages: im.snibgo.com

Locked