Save image to file fails

TeeChart for PHP
Post Reply
rustydiver
Newbie
Newbie
Posts: 22
Joined: Tue Apr 30, 2013 12:00 am

Save image to file fails

Post by rustydiver » Thu May 02, 2013 10:12 pm

Save image to file produces error and the image is not saved to the path/directory as it was in the evaluation version, even from the TeeChart samples..
Warning: imagepng(): 247 is not a valid Image resource in C:\xampp\htdocs\...........\sources\exports\PNGFormat.php on line 50
The Chart has been exported correctly !

I am guessing this code found as shown commented out in sources/exports/ImageExportFormat.php likely has some involvement..
/*
public function save($fileName) /*throws IOException {
$outfile = new File($fileName);
$ios = $this->ImageIO->createImageOutputStream($outfile);
$this->save2($ios);
$ios->close();
}
*/


public function save($ios) /* TODO throws IOException*/ {
}

AND...

Export SVG results in a page full of repeating errors (short list below):
Notice: Undefined variable: X in C:\xampp\htdocs\..........\sources\drawing\CanvasSVG.php on line 642

Notice: Undefined variable: Y in C:\xampp\htdocs\...........\sources\drawing\CanvasSVG.php on line 642

Warning: Missing argument 4 for CanvasSVG::TextOut(), called in C:\xampp\htdocs\..........\sources\drawing\CanvasSVG.php on line 642 and defined in C:\xampp\htdocs\CPDT\CPDT_lite\charts\sources\drawing\CanvasSVG.php on line 592

Notice: Undefined variable: text in C:\xampp\htdocs\..........\sources\drawing\CanvasSVG.php on line 605

Notice: Undefined variable: text in C:\xampp\htdocs\...........\sources\drawing\CanvasSVG.php on line 606

Notice: Undefined variable: text in C:\xampp\htdocs\...........\sources\drawing\CanvasSVG.php on line 632

Notice: Undefined variable: X in C:\xampp\htdocs\...........\sources\drawing\CanvasSVG.php on line 642

Notice: Undefined variable: Y in C:\xampp\htdocs\...........\sources\drawing\CanvasSVG.php on line 642
Etc, etc.

Yeray
Site Admin
Site Admin
Posts: 9509
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Save image to file fails

Post by Yeray » Mon May 06, 2013 2:16 pm

Hi,

Could you please arrange a simple example project we can run as is to reproduce the problem here?
Thanks in advance.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

rustydiver
Newbie
Newbie
Posts: 22
Joined: Tue Apr 30, 2013 12:00 am

Re: Save image to file fails

Post by rustydiver » Mon May 06, 2013 2:35 pm

Well this is a fresh download, and just using your examples under exporting>pictures (pick any of them, jpeg, png, etc) produces the error.

rustydiver
Newbie
Newbie
Posts: 22
Joined: Tue Apr 30, 2013 12:00 am

Re: Save image to file fails

Post by rustydiver » Mon May 06, 2013 2:36 pm

I might add, it worked in the evaluation version download.

rustydiver
Newbie
Newbie
Posts: 22
Joined: Tue Apr 30, 2013 12:00 am

Re: Save image to file fails

Post by rustydiver » Tue May 07, 2013 3:23 am

In sources/exports/PNGFormat.php as well as the other image exports, you reference this variable --> $ios (ImageOutputStream)

Like so..

Code: Select all

    public function save($ios) /* TODO throws IOException*/ {
        if ($this->width <= 0) {
            $this->width = 400;
        }

        if ($this->height <= 0) {
            $this->height = 300;
        }

        $img = $this->chart->image($this->width, $this->height);
        imagepng($this->chart->getGraphics3D()->img,$ios);
    }
The only other place I can find that variable, and where it is supposed to be defined, it seems, is at the bottom of sources/exports/ImageExportFormat.php

Below is copy/paste from ImageExportFormat.php exactly as it exists in my file (commented out -- not by me). Is there somewhere else $ios is defined?

Code: Select all

/*
    public function save($fileName) /*throws IOException {
        $outfile = new File($fileName);
        $ios = $this->ImageIO->createImageOutputStream($outfile);
        $this->save2($ios);
        $ios->close();
    }
*/


    public function save($ios) /* TODO throws IOException*/ {
    }        
}
Now in that code above, you also reference a variable --> $fileName I cannot find where that is defined. And I note that the errors thrown are like "247 is not a valid image resource". That number "247" is not coming from me, I simply click the button in your image export samples to save file and that error arrives. So where is that number generated?

Yeray
Site Admin
Site Admin
Posts: 9509
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Save image to file fails

Post by Yeray » Thu May 09, 2013 10:15 am

Hi,

I've reproduced this with the latest TeeChart version. We're currently investigating it.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Pep
Site Admin
Site Admin
Posts: 3272
Joined: Fri Nov 14, 2003 5:00 am
Contact:

Re: Save image to file fails

Post by Pep » Wed May 15, 2013 6:52 pm

Hello,

you were correct, the problem was just on our examples. As you added a destroy on our latest source code, once the render() method is called (this was to liberate memory in the case anyone wants to render chart several times).
This changes the way the charts have to be exported to a images, it's juts about lines order related, you have to call the export method before the render method (in the case of the available examples), for example :

Code: Select all

      $points->fillSampleValues(30);

      // Save Chart to text
      if(isset($_POST['submit'])) {
          if ($path!="") {
            if (realpath($path)) {
              $chart1->doInvalidate();  
              $chart1->getChart()->getExport()->getImage()->getPNG()->save($path."\\TChart.png");
              echo "The Chart has been exported correctly <br> !";
            }
          }
          else
          {
              echo "Correct path must be entered ! ";
          }
      }
              
      $chart1->render("chart1.png");
We've already changed this for the demos.

rsawoseyin
Newbie
Newbie
Posts: 2
Joined: Thu Jul 03, 2014 12:00 am

Re: Save image to file fails

Post by rsawoseyin » Thu Jul 03, 2014 2:02 pm

I know this is an old thread. But I have just downloaded the Jul-2013 version and I found that the image export bug is still there. I had the getExport() after render() in my code with the evaluation version, but the code crashes with this latest registered version - for the reason I now understand from this thread. I have not seen this important change highlighted in the version upgrade documentation.

By the way, if you getExport() before render() as advised, and you try to print the chart you see on screen into a .pdf file, you get no image - it's all black. To get a print, you need to first render() before getExport().

Another observation is that the charts I produce from the evaluation version are visibly better than from the latest registered version. With this latest version the legend lines look squashed between the rule lines. I will probably stay with the evaluation version for now.

Yeray
Site Admin
Site Admin
Posts: 9509
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Save image to file fails

Post by Yeray » Mon Jul 07, 2014 2:43 pm

Hello,

We made changes in the sources recently. I'll send you the latest sources and demos by mail so you can check if they work fine for you.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

rsawoseyin
Newbie
Newbie
Posts: 2
Joined: Thu Jul 03, 2014 12:00 am

Re: Save image to file fails

Post by rsawoseyin » Mon Jul 07, 2014 3:44 pm

Look at the attached .png files which compare the quality of charts from the 2010 version and your very latest (May-2014) version. You can see that the chart Legend in the 2014 version shows the lines separating the legend texts actually touching the texts. The chart from the 2010 version is of better quality.
Attachments
TChart2014-Sample.png
Legend lines are not adequately spaced for the legend texts
TChart2014-Sample.png (66.68 KiB) Viewed 47941 times
TChart2010-Sample.png
Crisp and clear Legend -lines are optimally spaced
TChart2010-Sample.png (71.4 KiB) Viewed 47912 times

Yeray
Site Admin
Site Admin
Posts: 9509
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Save image to file fails

Post by Yeray » Tue Jul 08, 2014 12:07 pm

Hello,

Thanks for reporting this.
We've made a few changes and fixed this problem with the legend.
I'll send you the new sources to the mail account you have registered in this forum.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply