Esempio n. 1
0
VALUE wkhtml_toimage_converter_create(VALUE self, VALUE settings, VALUE data) {
  wkhtmltoimage_global_settings* global_settings;
  wkhtmltoimage_converter* converter;
  char* data_cstr = NULL;

  if(rb_obj_is_kind_of(settings, cWkHtmlToImageGlobalSettings) == Qfalse) {
    rb_raise(rb_eArgError, "Wrong argument type, must be a GlobalSettings");
  }
  rb_check_frozen(self);

  if(!NIL_P(data)) {
    Check_Type(data, T_STRING);
    data_cstr = StringValueCStr(data);
  }

  Data_Get_Struct(settings, wkhtmltoimage_global_settings, global_settings);

  //Initialize on library load
  ////Initialize library before creating (will only if first call)
  //wkhtmltoimage_init(USE_GRAPHICS_INT);
  converter = wkhtmltoimage_create_converter(global_settings, data_cstr);

  OBJ_FREEZE(settings);

  return Data_Wrap_Struct(self, NULL, wkhtml_toimage_converter_free, converter);
}
Esempio n. 2
0
/* Main method convert image */
int main() {
	wkhtmltoimage_global_settings * gs;
	wkhtmltoimage_converter * c;
	const unsigned char * data;
	long len;

	/* Init wkhtmltoimage in graphics less mode */
	wkhtmltoimage_init(false);

	/*
	 * Create a global settings object used to store options that are not
	 * related to input objects, note that control of this object is parsed to
	 * the converter later, which is then responsible for freeing it
	 */
	gs = wkhtmltoimage_create_global_settings();

	/* We want to convert to convert the qstring documentation page */
	wkhtmltoimage_set_global_setting(gs, "in", "http://www.google.com/");
	wkhtmltoimage_set_global_setting(gs, "fmt", "jpeg");

	/* Create the actual converter object used to convert the pages */
	c = wkhtmltoimage_create_converter(gs, NULL);

	/* Call the progress_changed function when progress changes */
	wkhtmltoimage_set_progress_changed_callback(c, progress_changed);

	/* Call the phase _changed function when the phase changes */
	wkhtmltoimage_set_phase_changed_callback(c, phase_changed);

	/* Call the error function when an error occures */
	wkhtmltoimage_set_error_callback(c, error);

	/* Call the waring function when a warning is issued */
	wkhtmltoimage_set_warning_callback(c, warning);

	/* Perform the actual convertion */
	if (!wkhtmltoimage_convert(c))
		fprintf(stderr, "Convertion failed!");

	/* Output possible http error code encountered */
	printf("httpErrorCode: %d\n", wkhtmltoimage_http_error_code(c));

	len = wkhtmltoimage_get_output(c, &data);
	printf("%ld len\n", len);


	/* Destroy the converter object since we are done with it */
	wkhtmltoimage_destroy_converter(c);

	/* We will no longer be needing wkhtmltoimage funcionality */
	wkhtmltoimage_deinit();

	return 0;
}