```{index} single: write_to_png_stream (Cairo::Surface) ``` ```{index} single: Cairo::Surface::write_to_png_stream ``` # write_to_png_stream Writes the surface as a PNG by handing successive chunks of it to a callback of yours, and returns a status name. $surface->write_to_png_stream(sub { my ($data, $chunk) = @_; print {$fh} $chunk; }); The callback is called with two arguments: the optional `$data` value you passed after it, and the chunk of PNG bytes to consume. Its return value is ignored; to report a failure, die with a cairo status name such as `'write-error'`, which then becomes this method's result. The callback is only used during the call and is not retained afterwards. Dies if the cairo installed on this machine was built without PNG support. Wraps `cairo_surface_write_to_png_stream`.