Page 1 of 1

Save image to file fails

Posted: Thu May 02, 2013 10:12 pm
by 15965760
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.

Re: Save image to file fails

Posted: Mon May 06, 2013 2:16 pm
by yeray
Hi,

Could you please arrange a simple example project we can run as is to reproduce the problem here?
Thanks in advance.

Re: Save image to file fails

Posted: Mon May 06, 2013 2:35 pm
by 15965760
Well this is a fresh download, and just using your examples under exporting>pictures (pick any of them, jpeg, png, etc) produces the error.

Re: Save image to file fails

Posted: Mon May 06, 2013 2:36 pm
by 15965760
I might add, it worked in the evaluation version download.

Re: Save image to file fails

Posted: Tue May 07, 2013 3:23 am
by 15965760
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?

Re: Save image to file fails

Posted: Thu May 09, 2013 10:15 am
by yeray
Hi,

I've reproduced this with the latest TeeChart version. We're currently investigating it.

Re: Save image to file fails

Posted: Wed May 15, 2013 6:52 pm
by Pep
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.

Re: Save image to file fails

Posted: Thu Jul 03, 2014 2:02 pm
by 15969658
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.

Re: Save image to file fails

Posted: Mon Jul 07, 2014 2:43 pm
by yeray
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.

Re: Save image to file fails

Posted: Mon Jul 07, 2014 3:44 pm
by 15969658
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.

Re: Save image to file fails

Posted: Tue Jul 08, 2014 12:07 pm
by yeray
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.