<div dir="ltr">Hi.<br><br>I'm resizing and generating PNGs from SVG inputs.<br><br>I want the best possible quality but the downsampling of large input images to small output images seems to be quite crude.<br><br>I've tried looking at how to use set_filter but it's not obvious how to use this in conjunction with RSVG's render_rsvg_handle. I tried rendering to a recording surface and then using a surface pattern with a filter set but that didn't help. Here is an example of the Ruby code:<span class=""></span><span class=""></span><div><br></div><div><div><font face="monospace, monospace">def save_surface_to_png(input_surface, output_path, size)</font></div><div><font face="monospace, monospace"><span class="" style="white-space:pre">   </span>width, height = *size</font></div><div><span class="" style="white-space:pre"><font face="monospace, monospace">       </font></span></div><div><font face="monospace, monospace"><span class="" style="white-space:pre">    </span>surface = Cairo::ImageSurface.new(Cairo::FORMAT_ARGB32, width, height)</font></div><div><font face="monospace, monospace"><span class="" style="white-space:pre">      </span>context = Cairo::Context.new(surface)</font></div><div><font face="monospace, monospace"><span class="" style="white-space:pre">       </span>context.antialias = Cairo::ANTIALIAS_SUBPIXEL</font></div><div><span class="" style="white-space:pre"><font face="monospace, monospace">       </font></span></div><div><font face="monospace, monospace"><span class="" style="white-space:pre">    </span>pattern = Cairo::SurfacePattern.new(input_surface)</font></div><div><font face="monospace, monospace"><span class="" style="white-space:pre">  </span>pattern.set_filter(Cairo::FILTER_BEST)</font></div><div><span class="" style="white-space:pre"><font face="monospace, monospace">      </font></span></div><div><font face="monospace, monospace"><span class="" style="white-space:pre">    </span>context.set_source(pattern)</font></div><div><font face="monospace, monospace"><span class="" style="white-space:pre"> </span>context.rectangle(0,0,width,height)</font></div><div><font face="monospace, monospace"><span class="" style="white-space:pre"> </span>context.fill</font></div><div><span class="" style="white-space:pre"><font face="monospace, monospace">        </font></span></div><div><font face="monospace, monospace"><span class="" style="white-space:pre">    </span>context.target.write_to_png(output_path.to_s)</font></div><div><span class="" style="white-space:pre"><font face="monospace, monospace">       </font></span></div><div><font face="monospace, monospace"><span class="" style="white-space:pre">    </span>surface.finish</font></div><div><font face="monospace, monospace">end</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">def convert_svg_to_png_cairo(input_path, output_path, size)</font></div><div><font face="monospace, monospace"><span class="" style="white-space:pre">    </span>puts "#{input_path} -> #{output_path}"</font></div><div><font face="monospace, monospace"><span class="" style="white-space:pre"> </span>width, height = *size</font></div><div><span class="" style="white-space:pre"><font face="monospace, monospace">       </font></span></div><div><font face="monospace, monospace"><span class="" style="white-space:pre">    </span>surface = Cairo::RecordingSurface.new(0, 0, width, height)</font></div><div><font face="monospace, monospace"><span class="" style="white-space:pre">  </span>context = Cairo::Context.new(surface)</font></div><div><font face="monospace, monospace"><span class="" style="white-space:pre">       </span>context.antialias = Cairo::ANTIALIAS_SUBPIXEL</font></div><div><span class="" style="white-space:pre"><font face="monospace, monospace">       </font></span></div><div><font face="monospace, monospace"><span class="" style="white-space:pre">    </span>svg_handle = RSVG::Handle.new_from_file(input_path.to_s)</font></div><div><span class="" style="white-space:pre"><font face="monospace, monospace">    </font></span></div><div><font face="monospace, monospace"><span class="" style="white-space:pre">    </span>svg_dimensions = svg_handle.dimensions</font></div><div><font face="monospace, monospace"><span class="" style="white-space:pre">      </span>scale_factor = size[0].to_f / svg_dimensions.width.to_f</font></div><div><span class="" style="white-space:pre"><font face="monospace, monospace">     </font></span></div><div><font face="monospace, monospace"><span class="" style="white-space:pre">    </span>context.scale(scale_factor, scale_factor)</font></div><div><span class="" style="white-space:pre"><font face="monospace, monospace">   </font></span></div><div><font face="monospace, monospace"><span class="" style="white-space:pre">    </span>context.render_rsvg_handle(svg_handle)</font></div><div><span class="" style="white-space:pre"><font face="monospace, monospace">      </font></span></div><div><font face="monospace, monospace"><span class="" style="white-space:pre">    </span>context.show_page</font></div><div><span class="" style="white-space:pre"><font face="monospace, monospace">   </font></span></div><div><font face="monospace, monospace"><span class="" style="white-space:pre">    </span>save_surface_to_png(surface, output_path, size)</font></div><div><span class="" style="white-space:pre"><font face="monospace, monospace">     </font></span></div><div><font face="monospace, monospace"><span class="" style="white-space:pre">    </span>surface.finish</font></div><div><font face="monospace, monospace">end</font></div></div><div><br></div><div><br></div><div>It's not entirely obvious what I'm doing wrong or if it's even possible. Is there some way to set the filter quality used by RSVG?</div><div><br></div><div>Thanks</div><div>Samuel</div></div>