SVG in Bild konvertieren – Cloud SDK und REST API SVG zu Bild Durch die Konvertierung von SVG in Bildformate wie PNG oder JPEG ist die Kompatibilität mit allen Geräten und Software gewährleistet, da diese Formate überall unterstützt werden. Beispielsweise sind Tools wie Adobe Photoshop für die Arbeit mit Formaten wie PNG, JPEG oder TIFF optimiert. Darüber hinaus sind Rasterbilder häufig für bestimmte Zwecke erforderlich, beispielsweise für Social-Media-Beiträge oder E-Mail-Anhänge, bei denen Vektorformate möglicherweise nicht unterstützt werden.
Aspose.HTML Cloud v4.0 bietet die einfachste API zum Konvertieren von SVG -Dokumenten in Bilddateiformate mit hoher Qualität, einfach und schnell.
Der Artikel erklärt in einer Reihe von Codebeispielen, wie man ein SVG-Dokument in Bilddateiformate wie JPEG , PNG , GIF , TIFF  oder BMP  mit Aspose.HTML Cloud SDKs und REST API-Aufrufen. SDKs sind in PHP, C++, Python, C#, Ruby, Java, Android, Swift und Node.js verfügbar.
SDK-Beispiele für die SVG-zu-Bild-Konvertierung Ein häufiger Anwendungsfall für Aspose.HTML Cloud SDK-Funktionen ist die Dateiverarbeitung und -konvertierung. Mit dem Cloud SDK können Sie ein SVG-Dokument anhand seines Namens aus dem Speicher oder aus einer lokalen Datei auf Ihrem Laufwerk abrufen, es in ein bestimmtes Format konvertieren und es wieder im Speicher oder auf Ihrem lokalen Laufwerk speichern. Die folgenden Codebeispiele veranschaulichen, wie SVG mithilfe verschiedener SDKs und cURL für verschiedene Szenarien in ein Bild konvertiert wird.
Beispiel 1. SVG in JPG konvertieren JPG ist aufgrund seines kontrollierten Qualitätsverlusts bei der Komprimierung eines der am häufigsten verwendeten Bildformate. Dadurch eignet es sich ideal zum Speichern und Teilen von grafischen Inhalten wie Fotos, gescannten Kopien und digitalisierten Bildern über das Internet. Hier ist ein Beispiel für die Konvertierung einer lokalen SVG-Datei in das JPG-Format und das Speichern des Ergebnisses in einem lokalen Dateisystem mithilfe der Standardkonvertierungsoptionen.
C# Das folgende Beispiel zeigt die einfachste Möglichkeit, SVG in JPG  mit C# zu konvertieren. Eine lokale SVG-Datei wird in ein JPG-Bild konvertiert und in einem lokalen Dateisystem gespeichert. Sie können das C# SDK aus dem
GitHub-Repository  herunterladen.
Copy 1 // Initialize SDK API 
 2 var   api  =   new   HtmlApi("CLIENT_ID" ,  "CLIENT_SECRET" ).ConvertApi ;
 3 
 4 // Convert SVG to JPG 
 5 var   result  =   await  api.ConvertAsync ("test.svg" ,  "test.jpg" );Java Das folgende Beispiel zeigt, wie man SVG in JPG  mit Java konvertiert. Eine lokale SVG-Datei wird in ein JPG-Bild konvertiert und in einem lokalen Dateisystem gespeichert. Sie können das Java SDK aus dem
GitHub-Repository  herunterladen.
Copy  1 Configuration.setBasePath ("https://api.aspose.cloud" );
   2 setAuthPath ("https://api.aspose.cloud/connect/token" );
  3 
  4   api  =   new   HtmlApi("CLIENT_ID" ,  "CLIENT_SECRET" );
  5 
  6   builder  =   new   ConverterBuilder()
  7                  .fromLocalFile ("input.svg" )
  8                  .saveToLocal ("output.jpeg" );
  9 
 10   result  =   api.convert (builder);C++ Das folgende Beispiel zeigt, wie man mithilfe der C++-Sprache SVG in JPG  konvertiert. Eine lokale SVG-Datei wird in ein JPG-Bild konvertiert und in einem lokalen Dateisystem gespeichert.
Copy  1 // Get current directory 
  2 std ::string  cur_dir (argv[ 0] );
  3 int   pos  =   cur_dir.find_last_of ("/\\" );
  4   =   cur_dir.substr (0,  pos  +   1);  // Include the last slash 
  5 std ::wstring  w_cur_dir (cur_dir.begin (),  cur_dir.end ());
  6 
  7 const   utility::string_t  clientId  =   L"XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" ;
  8 const   utility::string_t  clientSecret  =   L"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" ;
  9 const   utility::string_t  basePath  =   L"https://api.aspose.cloud/v4.0" ;
 10 const   utility::string_t  authPath  =   L"https://api.aspose.cloud/connect/token" ;
 11 
 12 // Create configuration for authorization 
 13 std ::shared_ptr< ApiConfiguration>   apiConfig (new   ApiConfiguration(clientId,  clientSecret,  basePath,  authPath));
 14 
 15 // Create client from configuration 
 16 std ::shared_ptr< ApiClient>   apiClient (new   ApiClient(apiConfig));
 17 
 18 // Create ConversionApi 
 19 std ::shared_ptr< ConversionApi>   api  =   std::make_shared< ConversionApi> (apiClient);
 20 
 21 // File name for conversion 
 22 utility ::string_t  src  =   w_cur_dir  +   L"test.svg" ;
 23 utility ::string_t  dst  =   w_cur_dir  +   L"result.jpeg" ;
 24 
 25 //Conversion 
 26   result  =   api-> convertLocalToLocal(src,  dst);
 27 
 28 // Check the result file 
 29   re  =   result-> getFile();
 30 std ::ifstream  f (re.c_str ());
 31 if (! f.good ())
 32 
 33      throw   std::runtime_error("Conversion failed" );
 34 Python Das folgende Beispiel zeigt, wie man SVG in JPG  in der Python-Sprache umwandelt. Eine lokale SVG-Datei wird in ein JPG-Bild konvertiert und in einem lokalen Dateisystem gespeichert. Sie können das Python SDK aus dem
GitHub-Repository  herunterladen.
Copy  1 from  asposehtmlcloud.configuration   import   Configuration 
   2   asposehtmlcloud.api .html_api   import   HtmlApi 
  3   asposehtmlcloud.api_client   import   ApiClient   as  Client
  4   asposehtmlcloud.rest   import   ApiException 
  5 
  6   =   Configuration(apiKey= "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" ,
  7                                appSid= "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" ,
  8                                basePath= "https://api.aspose.cloud/v4.0" ,
  9                                authPath= "https://api.aspose.cloud/connect/token" ,
 10                                debug= True)
 11   =   Client(configuration)
 12   =   HtmlApi(client)
 13 
 14 try :
 15      res  =   html_api.convertApi .convert_local_to_local (input_file= "test.svg" ,  output_file= "test.jpeg" )
 16   ApiException  as  ex:
 17      print("Exception" )
 18      print("Info: "   +   str(ex))
 19      raise  exPHP Das folgende Beispiel zeigt, wie man SVG in JPG  mit PHP konvertiert. Eine lokale SVG-Datei wird in ein JPG-Bild konvertiert und in einem lokalen Dateisystem gespeichert. Sie können das PHP SDK aus dem
GitHub-Repository  herunterladen.
Copy  1 <? php
  2 require_once (__DIR__  .  ' / vendor/ autoload.php ' );
  3 
  4   =   array(
  5 	 "basePath"   =>   "https://api.aspose.cloud/v4.0" ,
  6 	 "authPath"   =>   "https://api.aspose.cloud/connect/token" ,
  7 	 "apiKey"   =>   "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" ,
  8 	 "appSID"   =>   "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" ,
  9 	 "defaultUserAgent"   =>   "Webkit" 
 10 
 11 
 12   =   new   Client\ Invoker\ Api\ HtmlApi($conf);
 13 
 14   =   ' input.svg ' ;
 15   =   ' output.jpeg ' ;
 16 
 17 try   {
 18      // Request to server Api 
 19      $result  =   $api_html-> convertLocalToLocal($src,  $dst);
 20      print_r($result);
 21   catch   (Exception  $e)  {
 22      echo  ' Exception  when  calling  HtmlApi-> convertLocalToLocal:  ' ,  $e-> getMessage(),  PHP_EOL;
 23 
 24 
 25 ?> Ruby Das folgende Beispiel zeigt, wie man mithilfe der Ruby-Sprache SVG in JPG  konvertiert. Eine lokale SVG-Datei wird in ein JPG-Bild konvertiert und in einem lokalen Dateisystem gespeichert. Sie können das Ruby SDK aus dem
GitHub-Repository  herunterladen.
Copy  1 #   load  the  gem
  2   ' aspose_html_cloud' 
  3 
  4 #   Get  keys  from  aspose  site.
  5 #   There  is  free  quota  available. 
  6 #   For  more  details,  see  https://purchase.aspose.cloud/pricing 
  7 
  8   =   {
  9      "basePath" :"https://api.aspose.cloud/v4.0" ,
 10      "authPath" :"https://api.aspose.cloud/connect/token" ,
 11      "apiKey" :"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" ,
 12      "appSID" :"XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" ,
 13      "debug" :true 
 14 
 15 
 16   =   AsposeHtml::HtmlApi.new   CONFIG
 17 
 18   =   "test.svg"    #   String  |   Full  path  to  the  input  file.
 19   =   "test.jpeg"    #   String  |   Full  path  to  the  result.
 20 
 21 
 22    # Convert  the  document  from  the  local  file  and  save  result  to  the  local  file.
 23    result  =   api_instance.convert_local_to_local (src,  dst)
 24    p  result
 25   AsposeHtml::ApiError  =>   e
 26    puts  "Exception when calling api_instance.convert_local_to_local: #{e}" 
 27 Node.js Das folgende Beispiel zeigt, wie SVG in JPG  mithilfe der Node.js-Sprache konvertiert wird. Eine lokale SVG-Datei wird in ein JPG-Bild konvertiert und in einem lokalen Dateisystem gespeichert.
Copy  1 // Get keys from aspose site. 
  2 // There is free quota available. 
  3 // For more details, see https://purchase.aspose.cloud/pricing 
  4 	
  5 var   conf  =   {
  6      "basePath" :"https://api.aspose.cloud/v4.0" ,
  7      "authPath" :"https://api.aspose.cloud/connect/token" ,
  8      "apiKey" :"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" ,
  9      "appSID" :"XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" ,
 10      "defaultUserAgent" :"NodeJsWebkit" 
 11 
 12 
 13 var   api  =   require(' @asposecloud / aspose- html- cloud' );
 14 
 15 // Create Conversion Api object 
 16 var   conversionApi  =   new   api.ConversionApi (conf);
 17 
 18 var   src  =   "/path/to/src/test.svg" ;  // {String} Source document. 
 19 var   dst  =   "/path/to/dst/test.jpeg" ;  // {String} Result document. 
 20 var   opts  =   null ;
 21 
 22 var   callback  =   function(error,  data,  response)  {
 23    if   (error)  {
 24      console.error (error);
 25    }  else   {
 26      console.log (data);
 27    }
 28 
 29 
 30 convertLocalToLocal (src,  dst,  opts,  callback);Swift Das folgende Beispiel zeigt, wie man mithilfe der Swift-Sprache SVG in JPG  konvertiert. Eine lokale SVG-Datei wird in ein JPG-Bild konvertiert und in einem lokalen Dateisystem gespeichert. Sie können das Swift SDK aus dem
GitHub-Repository  herunterladen.
Copy  1 import   Alamofire 
  2 import   Foundation 
  3 import   XCTest 
  4 import   AsposeHtmlCloud 
  5 
  6 static   let  fm  =   FileManager.default 
  7   resourceDir  =   fm.homeDirectoryForCurrentUser .appendingPathComponent ("Documents/Aspose.HTML.Cloud.SDK.Swift/Tests/AsposeHtmlCloudTests/Resources" )
  8   resultDir  =   fm.homeDirectoryForCurrentUser .appendingPathComponent ("Documents/Aspose.HTML.Cloud.SDK.Swift/Tests/AsposeHtmlCloudTests/TestResult" )
  9 
 10   url (forResource  fileName:  String)  ->   URL  {
 11 	 return   resourceDir.appendingPathComponent (fileName)
 12 
 13 
 14   fileExist (name:  String)  ->   Bool  {
 15 	 return   FileManager.default .fileExists (atPath:  name)
 16 
 17 
 18 setConfig (
 19 	 basePath:  "https://api.aspose.cloud/v4.0" ,
 20 	 authPath:  "https://api.aspose.cloud/connect/token" ,
 21 	 apiKey:  "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" ,
 22 	 appSID:  "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" ,
 23 	 debugging:  true 
 24 
 25 
 26   fileName  =   "test.svg" 
 27   format  =   "jpeg" 
 28   src  =   url(forResource:  fileName).absoluteString 
 29 
 30   expectation  =   self.expectation (description:  "testConvert to \(format)" )
 31   dst  =   resultDir.appendingPathComponent ("Output.\(format)" ).absoluteString 
 32 convertLocalToLocal (src:  src,  dst:  dst,  options:  nil)  {  (data,  error)  in
 33 
 34 	 guard  error  ==   nil  else   {
 35 		 XCTFail("Error convert SVG to \(format)). Error=\(error!.localizedDescription)" )
 36 		 return 
 37 	 }
 38 	 let  resultPath  =   data! .file ! 
 39 	 XCTAssertTrue(fileExist(name:  resultPath))
 40 	 expectation.fulfill ()
 41 
 42 waitForExpectations (timeout:  100.0 ,  handler:  nil)Java/Android Das folgende Beispiel zeigt, wie man SVG in JPG  mit Java/Android konvertiert. Eine lokale SVG-Datei wird in ein JPG-Bild konvertiert und in einem lokalen Dateisystem gespeichert. Sie können das Java/Android SDK aus dem
GitHub-Repository  herunterladen.
Copy  1 Configuration.setBasePath ("https://api.aspose.cloud" );
   2 setAuthPath ("https://api.aspose.cloud/connect/token" );
  3 
  4   api  =   new   HtmlApi("CLIENT_ID" ,  "CLIENT_SECRET" );
  5 
  6   builder  =   new   ConverterBuilder()
  7                  .fromLocalFile ("input.svg" )
  8                  .saveToLocal ("output.jpeg" );
  9 
 10   result  =   api.convert (builder);CURL Laden Sie eine lokale Datei mithilfe der
Speicher-API  in den Speicher hoch. Rufen Sie die REST-API auf, um die Konvertierung auszuführen (im Beispiel unten). Laden Sie das Konvertierungsergebnis mithilfe der
Speicher-API  aus dem Speicher herunter. Das folgende Beispiel zeigt, wie man mithilfe der REST-API SVG in JPG  konvertiert. Eine lokale SVG-Datei wird in ein JPG-Bild konvertiert und in einem lokalen Dateisystem gespeichert. Führen Sie einige erforderliche Schritte aus:
Copy 1 curl  - X  POST  - v  \ 
  2 	 "https://api.aspose.cloud/v4.0/html/conversion/svg-jpg"   \ 
 3      - d  "{'InputPath': '/testpage.svg', 'OutputFile': 'test.jpg'}"   \ 
 4      - H  "Content-Type: application/json"   \ 
 5      - H  "Authorization:Bearer <JWT_token>" Die Konvertierung von SVG in JPG erfolgt mit den Standardkonvertierungsoptionen : Die Breite und Höhe des resultierenden JPG-Dokuments entsprechen A4 und alle Ränder haben den Wert Null.
Beispiel 2. Konvertieren Sie SVG in PNG mit explizit angegebenen Optionen Das PNG-Bildformat wird häufig zum Übertragen von Bildern über das Netzwerk, zum Anzeigen von Fotos und Grafiken auf Webseiten und zum Speichern von Bildern im Cloud-Speicher verwendet. PNG unterstützt Transparenz und ist für das Web optimiert. Die Konvertierung von SVG in PNG bietet umfassende Kompatibilität über Plattformen und Anwendungen hinweg und erleichtert so die Anzeige und Weitergabe von Bildern. Das folgende Beispiel zeigt, wie man eine SVG-Datei mit explizit angegebenen Optionen in PNG konvertiert und das Ergebnis in einem lokalen Dateisystem speichert.
C# Das folgende SDK-Beispiel zeigt, wie man SVG in PNG  mit C# konvertiert. Das SVG wird aus einem lokalen Dateisystem entnommen, in PNG konvertiert und auf dem lokalen Laufwerk gespeichert. Sie können das C# SDK aus dem
GitHub-Repository  herunterladen.
Copy  1 // Initialize SDK API 
  2 var   api  =   new   HtmlApi("CLIENT_ID" ,  "CLIENT_SECRET" ).ConvertApi ;
  3 
  4 // Create an options instance and specify options for SVG to PNG conversion 
  5 var   options  =   new   ImageConversionOptions()
  6                  .SetHeight (800)
  7                  .SetWidth (1000)
  8                  .SetLeftMargin (10)
  9                  .SetRightMargin (10)
 10                  .SetBottomMargin (10)
 11                  .SetTopMargin (10);
 12 
 13 // Convert SVG to PNG 
 14 var   result  =   await  api.ConvertAsync ("test.svg" ,  "test.png" ,  options);Java Das folgende Beispiel zeigt, wie man SVG in PNG  mit Java konvertiert. Das SVG wird aus einem lokalen Dateisystem entnommen, in PNG konvertiert und im lokalen Dateisystem gespeichert. Sie können das Java SDK aus dem
GitHub-Repository  herunterladen.
Copy  1 Configuration.setBasePath ("https://api.aspose.cloud" );
   2 setAuthPath ("https://api.aspose.cloud/connect/token" );
  3 
  4   api  =   new   HtmlApi("CLIENT_ID" ,  "CLIENT_SECRET" );
  5 
  6   opt  =   new   ImageConversionOptions()
  7                          .setWidth (600)
  8                          .setHeight (900)
  9                          .setTopMargin (20)
 10                          .setBottomMargin (20)
 11                          .setLeftMargin (20)
 12                          .setRightMargin (20);
 13 
 14   builder  =   new   ConverterBuilder()
 15                  .fromLocalFile ("input.svg" )
 16                  .useOptions (opt)
 17                  .saveToLocal ("output.png" );
 18 
 19   result  =   api.convert (builder);C++ Das folgende Beispiel zeigt, wie man SVG in PNG  mit C++ konvertiert. Das SVG wird aus einem lokalen Dateisystem entnommen, in PNG konvertiert und im lokalen Dateisystem gespeichert.
Copy  1 // Get current directory 
  2 std ::string  cur_dir (argv[ 0] );
  3 int   pos  =   cur_dir.find_last_of ("/\\" );
  4   =   cur_dir.substr (0,  pos  +   1);  // Include the last slash 
  5 std ::wstring  w_cur_dir (cur_dir.begin (),  cur_dir.end ());
  6 
  7 const   utility::string_t  clientId  =   L"XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" ;
  8 const   utility::string_t  clientSecret  =   L"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" ;
  9 const   utility::string_t  basePath  =   L"https://api.aspose.cloud/v4.0" ;
 10 const   utility::string_t  authPath  =   L"https://api.aspose.cloud/connect/token" ;
 11 
 12 // Create configuration for authorization 
 13 std ::shared_ptr< ApiConfiguration>   apiConfig (new   ApiConfiguration(clientId,  clientSecret,  basePath,  authPath));
 14 
 15 // Create client from configuration 
 16 std ::shared_ptr< ApiClient>   apiClient (new   ApiClient(apiConfig));
 17 
 18 // Create ConversionApi 
 19 std ::shared_ptr< ConversionApi>   api  =   std::make_shared< ConversionApi> (apiClient);
 20 
 21 // File name for conversion 
 22 utility ::string_t  src  =   w_cur_dir  +   L"test.svg" ;
 23 utility ::string_t  dst  =   w_cur_dir  +   L"result.png" ;
 24 
 25 std ::shared_ptr< ConversionOptions>   opts  =   std::make_shared< ConversionOptions> ();
 26 -> setWidth(800)
 27      -> setHeight(600)
 28      -> setLeftMargin(10)
 29      -> setRightMargin(10)
 30      -> setTopMargin(10)
 31      -> setBottomMargin(10);
 32 
 33 //Conversion 
 34   result  =   api-> convertLocalToLocal(src,  dst,  opts);
 35 
 36 // Check the result file 
 37   re  =   result-> getFile();
 38 std ::ifstream  f (re.c_str ());
 39 if (! f.good ())
 40 
 41      throw   std::runtime_error("Conversion failed" );
 42 Python Das folgende Beispiel zeigt, wie man SVG in PNG  mit der Python-Sprache konvertiert. Das SVG wird aus einem lokalen Dateisystem entnommen, in PNG konvertiert und auf dem lokalen Laufwerk gespeichert. Sie können das Python SDK aus dem
GitHub-Repository  herunterladen.
Copy  1 from  asposehtmlcloud.configuration   import   Configuration 
   2   asposehtmlcloud.api .html_api   import   HtmlApi 
  3   asposehtmlcloud.api_client   import   ApiClient   as  Client
  4   asposehtmlcloud.rest   import   ApiException 
  5 
  6   =   Configuration(apiKey= "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" ,
  7                                appSid= "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" ,
  8                                basePath= "https://api.aspose.cloud/v4.0" ,
  9                                authPath= "https://api.aspose.cloud/connect/token" ,
 10                                debug= True)
 11   =   Client(configuration)
 12   =   HtmlApi(client)
 13 
 14   =   {
 15      ' width' :  600,
 16      ' height' :  900,
 17      ' topmargin' :  20,
 18      ' bottommargin' :  20,
 19      ' leftmargin' :  20,
 20      ' rightmargin' :  20
 21 
 22 
 23 try :
 24      res  =   html_api.convertApi .convert_local_to_local (input_file= "test.svg" ,  output_file= "test.png" ,  options= options)
 25   ApiException  as  ex:
 26      print("Exception" )
 27      print("Info: "   +   str(ex))
 28      raise  exPHP Das folgende Beispiel zeigt, wie man SVG in PNG  mit PHP konvertiert. Das SVG wird aus einem lokalen Dateisystem entnommen, in PNG konvertiert und im lokalen Dateisystem gespeichert. Sie können das PHP SDK aus dem
GitHub-Repository  herunterladen.
Copy  1 <? php
  2 require_once (__DIR__  .  ' / vendor/ autoload.php ' );
  3 
  4   =   array(
  5 	 "basePath"   =>   "https://api.aspose.cloud/v4.0" ,
  6 	 "authPath"   =>   "https://api.aspose.cloud/connect/token" ,
  7 	 "apiKey"   =>   "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" ,
  8 	 "appSID"   =>   "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" ,
  9 	 "defaultUserAgent"   =>   "Webkit" 
 10 
 11 
 12   =   new   Client\ Invoker\ Api\ HtmlApi($conf);
 13 
 14   =   ' input.svg ' ;
 15   =   ' output.png ' ;
 16 
 17   =   [ 
 18      ' width'   =>   800,
 19      ' height'   =>   600,
 20      ' left_margin'   =>   20,
 21      ' right_margin'   =>   20,
 22      ' top_margin'   =>   20,
 23      ' bottom_margin'   =>   20
 24 ] ;
 25 
 26 
 27 try   {
 28      // Request to server Api 
 29      $result  =   $api_html-> convertLocalToLocal($src,  $dst,  $options);
 30      print_r($result);
 31   catch   (Exception  $e)  {
 32      echo  ' Exception  when  calling  HtmlApi-> convertLocalToLocal:  ' ,  $e-> getMessage(),  PHP_EOL;
 33 
 34 ?> Ruby Das folgende Beispiel zeigt, wie man mithilfe der Ruby-Sprache SVG in PNG  konvertiert. Das SVG wird aus einem lokalen Dateisystem entnommen, in PNG konvertiert und auf dem lokalen Laufwerk gespeichert. Sie können das Ruby SDK aus dem
GitHub-Repository  herunterladen.
Copy  1 #   load  the  gem
  2   ' aspose_html_cloud' 
  3 
  4 #   Get  keys  from  aspose  site.
  5 #   There  is  free  quota  available. 
  6 #   For  more  details,  see  https://purchase.aspose.cloud/pricing 
  7 
  8 
  9   =   {
 10      "basePath" :"https://api.aspose.cloud/v4.0" ,
 11      "authPath" :"https://api.aspose.cloud/connect/token" ,
 12      "apiKey" :"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" ,
 13      "appSID" :"XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" ,
 14      "debug" :true 
 15 
 16 
 17   =   AsposeHtml::HtmlApi.new   CONFIG
 18 
 19   =   "test.svg"   #   String  |   Source  file.
 20   =   "test.png"   #   String  |   Result  file.
 21 
 22   =   { 
 23    width:  700,        #   Float  |   Resulting  image  width  in  pixels. 
 24    height:  1000,      #   Float  |   Resulting  image  height  in  pixels. 
 25    left_margin:  40,   #   Float  |   Left  resulting  image  margin  in  pixels.
 26    right_margin:  40,  #   Float  |   Right  resulting  image  margin  in  pixels.
 27    top_margin:  50,    #   Float  |   Top  resulting  image  margin  in  pixels.
 28    bottom_margin:  50  #   Float  |   Bottom  resulting  image  margin  in  pixels.
 29 
 30 
 31 
 32    # Convert  the  HTML  file  from  the  local  file  and  save  result  to  the  local  file.
 33    result  =   api_instance.convert_local_to_local (src,  dst,  opts)
 34    p  result
 35   AsposeHtml::ApiError  =>   e
 36    puts  "Exception when calling api_instance.convert_local_to_local: #{e}" 
 37 Node.js Das folgende Beispiel zeigt, wie SVG in PNG  mithilfe der Node.js-Sprache konvertiert wird. Das SVG wird aus einem lokalen Dateisystem entnommen, in PNG konvertiert und im lokalen Dateisystem gespeichert.
Copy  1 // Get keys from aspose site. 
  2 // There is free quota available. 
  3 // For more details, see https://purchase.aspose.cloud/pricing 
  4 	
  5 var   conf  =   {
  6      "basePath" :"https://api.aspose.cloud/v4.0" ,
  7      "authPath" :"https://api.aspose.cloud/connect/token" ,
  8      "apiKey" :"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" ,
  9      "appSID" :"XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" ,
 10      "defaultUserAgent" :"NodeJsWebkit" 
 11 
 12 
 13 var   api  =   require(' @asposecloud / aspose- html- cloud' );
 14 
 15 // Create Conversion Api object 
 16 var   conversionApi  =   new   api.ConversionApi (conf);
 17 
 18 var   src  =   "/path/to/src/test.svg" ;  // {String} Source document. 
 19 var   dst  =   "/path/to/dst/test.png" ;  // {String} Result document. 
 20 var   opts  =   {
 21      ' width' :  600,
 22      ' height' :  800,
 23      ' leftMargin' :  10,
 24      ' rightMargin' :  20,
 25      ' topMargin' :  30,
 26      ' bottomMargin' :  40
 27 
 28 
 29 var   callback  =   function(error,  data,  response)  {
 30    if   (error)  {
 31      console.error (error);
 32    }  else   {
 33      console.log (data);
 34    }
 35 
 36 
 37 convertLocalToLocal (src,  dst,  opts,  callback);Swift Das folgende Beispiel zeigt, wie die Swift-Sprachanwendung SVG in PNG  konvertiert. Das SVG wird aus einem lokalen Dateisystem entnommen, in PNG konvertiert und auf dem lokalen Laufwerk gespeichert. Sie können das Swift SDK aus dem
GitHub-Repository  herunterladen.
Copy  1 import   Alamofire 
  2 import   Foundation 
  3 import   XCTest 
  4 import   AsposeHtmlCloud 
  5 
  6 static   let  fm  =   FileManager.default 
  7   resourceDir  =   fm.homeDirectoryForCurrentUser .appendingPathComponent ("Documents/Aspose.HTML.Cloud.SDK.Swift/Tests/AsposeHtmlCloudTests/Resources" )
  8   resultDir  =   fm.homeDirectoryForCurrentUser .appendingPathComponent ("Documents/Aspose.HTML.Cloud.SDK.Swift/Tests/AsposeHtmlCloudTests/TestResult" )
  9 
 10   url (forResource  fileName:  String)  ->   URL  {
 11 	 return   resourceDir.appendingPathComponent (fileName)
 12 
 13 
 14   fileExist (name:  String)  ->   Bool  {
 15 	 return   FileManager.default .fileExists (atPath:  name)
 16 
 17 
 18 setConfig (
 19 	 basePath:  "https://api.aspose.cloud/v4.0" ,
 20 	 authPath:  "https://api.aspose.cloud/connect/token" ,
 21 	 apiKey:  "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" ,
 22 	 appSID:  "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" ,
 23 	 debugging:  true 
 24 
 25 
 26   fileName  =   "test.svg" 
 27   format  =   "png" 
 28   src  =   url(forResource:  fileName).absoluteString 
 29   options  =   Options(width:  800,  height:  600,  leftMargin:  10,
 30          rightMargin:  10,  topMargin:  10,  bottomMargin:  10)
 31 
 32 
 33   expectation  =   self.expectation (description:  "testConvert to \(format)" )
 34   dst  =   resultDir.appendingPathComponent ("Output.\(format)" ).absoluteString 
 35 convertLocalToLocal (src:  src,  dst:  dst,  options:  options)  {  (data,  error)  in
 36 
 37 	 guard  error  ==   nil  else   {
 38 		 XCTFail("Error convert SVG to \(format)). Error=\(error!.localizedDescription)" )
 39 		 return 
 40 	 }
 41 	 let  resultPath  =   data! .file ! 
 42 	 XCTAssertTrue(fileExist(name:  resultPath))
 43 	 expectation.fulfill ()
 44 
 45 waitForExpectations (timeout:  100.0 ,  handler:  nil)Java/Android Das folgende Beispiel zeigt, wie man SVG in PNG  mit Java/Android konvertiert. Das SVG wird aus einem lokalen Dateisystem entnommen, in PNG konvertiert und im lokalen Dateisystem gespeichert. Sie können das Java/Android SDK aus dem
GitHub-Repository  herunterladen.
Copy  1 Configuration.setBasePath ("https://api.aspose.cloud" );
   2 setAuthPath ("https://api.aspose.cloud/connect/token" );
  3 
  4   api  =   new   HtmlApi("CLIENT_ID" ,  "CLIENT_SECRET" );
  5 
  6   opt  =   new   ImageConversionOptions()
  7                          .setWidth (600)
  8                          .setHeight (900)
  9                          .setTopMargin (20)
 10                          .setBottomMargin (20)
 11                          .setLeftMargin (20)
 12                          .setRightMargin (20);
 13 
 14   builder  =   new   ConverterBuilder()
 15                  .fromLocalFile ("input.svg" )
 16                  .useOptions (opt)
 17                  .saveToLocal ("output.png" );
 18 
 19   result  =   api.convert (builder);CURL Laden Sie eine lokale Datei mithilfe der
Speicher-API  in den Speicher hoch. Rufen Sie die REST-API auf, um die Konvertierung auszuführen (im Beispiel unten). Laden Sie das Konvertierungsergebnis mithilfe der
Speicher-API  aus dem Speicher herunter. Das folgende Beispiel zeigt, wie man mithilfe der REST-API SVG in PNG  konvertiert. Das SVG wird aus einem lokalen Dateisystem entnommen, in PNG konvertiert und auf dem lokalen Laufwerk gespeichert.
Bitte unternehmen Sie ein paar Schritte:
Copy 1 curl  - X  POST  - v  \ 
  2 	 "https://api.aspose.cloud/v4.0/html/conversion/svg-png"   \ 
 3      - d  "{'InputPath': '/testpage.svg', 'OutputFile': 'test.png', 'Options': {'Width':1000, 'Height': 800, 'LeftMargin': 10, 'RightMargin': 10, 'TopMargin': 10, 'BottomMargin': 10}}"   \ 
 4      - H  "Content-Type: application/json"   \ 
 5      - H  "Authorization: bearer <token>" Weitere Einzelheiten zu den verfügbaren Konvertierungsparametern für SVG-Dateien finden Sie im Abschnitt
SDK-Konvertierungsoptionen .
Beispiel 3. Konvertieren Sie SVG in GIF im Cloud-Speicher Mit Aspose.HTML Cloud können Sie eine SVG-Datei aus Ihrem Cloud-Speicher abrufen und das konvertierte Ergebnis mithilfe der Standardkonvertierungsoptionen wieder in der Cloud speichern.
GIF-Bilder werden plattform-, geräte- und webbrowserübergreifend weitgehend unterstützt und gewährleisten so eine konsistente Anzeige und Benutzerzugänglichkeit. Das Konvertieren von SVG in GIF kann die Grafik vereinfachen und sie für verschiedene Anwendungen zugänglicher machen, die SVG möglicherweise nicht vollständig unterstützen.
C# Das folgende Beispiel zeigt, wie man SVG in GIF  mit C# konvertiert. Eine SVG-Datei wird aus dem Cloud-Speicher abgerufen, in GIF konvertiert und dann wieder im Cloud-Speicher gespeichert. Sie können das C# SDK aus dem
GitHub-Repository  herunterladen.
Copy 1 // Initialize SDK API 
 2 var   api  =   new   HtmlApi("CLIENT_ID" ,  "CLIENT_SECRET" ).ConvertApi ;
 3 
 4 // Convert SVG to GIF 
 5 var   builder  =   new   ConverterBuilder()
 6                  .FromStorageFile ("/test.svg" )
 7                  .ToStorageFile ("/test.gif" );
 8                 
 9 var   result  =   await  api.ConvertAsync (builder);Java Das folgende Beispiel zeigt, wie man SVG in GIF  mit Java konvertiert. Eine SVG-Datei wird aus dem Cloud-Speicher abgerufen, in GIF konvertiert und dann wieder im Cloud-Speicher gespeichert. Sie können das Java SDK aus dem
GitHub-Repository  herunterladen.
Copy  1 Configuration.setBasePath ("https://api.aspose.cloud" );
   2 setAuthPath ("https://api.aspose.cloud/connect/token" );
  3 
  4   api  =   new   HtmlApi("CLIENT_ID" ,  "CLIENT_SECRET" );
  5 
  6   builder  =   new   ConverterBuilder()
  7                  .fromStorageFile ("input.svg" )
  8                  .saveToStorage ("output.gif" );
  9 
 10   result  =   api.convert (builder);C++ Das folgende Beispiel zeigt, wie man SVG in GIF  mit C++ konvertiert. Eine SVG-Datei wird aus dem Cloud-Speicher abgerufen, in GIF konvertiert und dann wieder im Cloud-Speicher gespeichert.
Copy  1 const   utility::string_t  clientId  =   L"XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" ;
  2 const   utility::string_t  clientSecret  =   L"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" ;
  3 const   utility::string_t  basePath  =   L"https://api.aspose.cloud/v4.0" ;
  4 const   utility::string_t  authPath  =   L"https://api.aspose.cloud/connect/token" ;
  5 
  6 // Create configuration for authorization 
  7 std ::shared_ptr< ApiConfiguration>   apiConfig (new   ApiConfiguration(clientId,  clientSecret,  basePath,  authPath));
  8 
  9 // Create client from configuration 
 10 std ::shared_ptr< ApiClient>   apiClient (new   ApiClient(apiConfig));
 11 
 12 // Create ConversionApi 
 13 std ::shared_ptr< ConversionApi>   api  =   std::make_shared< ConversionApi> (apiClient);
 14 
 15 // File name for conversion 
 16 utility ::string_t  src  =   L"file/in/storage/index.svg" ;
 17 utility ::string_t  dst  =   L"result/in/storage/result.gif" ;
 18 
 19 //Conversion 
 20   result  =   api-> convertStorageToStorage(src,  dst);Python Das folgende Beispiel zeigt, wie man SVG in GIF  mithilfe der Python-Sprache konvertiert. Eine SVG-Datei wird aus dem Cloud-Speicher abgerufen, in GIF konvertiert und dann wieder im Cloud-Speicher gespeichert. Sie können das Python SDK aus dem
GitHub-Repository  herunterladen.
Copy  1 from  asposehtmlcloud.configuration   import   Configuration 
   2   asposehtmlcloud.api .html_api   import   HtmlApi 
  3   asposehtmlcloud.api_client   import   ApiClient   as  Client
  4   asposehtmlcloud.rest   import   ApiException 
  5 
  6   =   Configuration(apiKey= "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" ,
  7                                appSid= "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" ,
  8                                basePath= "https://api.aspose.cloud/v4.0" ,
  9                                authPath= "https://api.aspose.cloud/connect/token" ,
 10                                debug= True)
 11   =   Client(configuration)
 12   =   HtmlApi(client)
 13 
 14 try :
 15      res  =   html_api.convertApi .convert_storage_to_storage (input_file= "test.svg" ,  output_file= "test.gif" ,
 16                                                           storage_name= None)
 17   ApiException  as  ex:
 18      print("Exception" )
 19      print("Info: "   +   str(ex))
 20      raise  exPHP Das folgende Beispiel zeigt, wie man SVG in GIF  mit PHP konvertiert. Eine SVG-Datei wird aus dem Cloud-Speicher abgerufen, in GIF konvertiert und dann wieder im Cloud-Speicher gespeichert. Sie können das PHP SDK aus dem
GitHub-Repository  herunterladen.
Copy  1 <? php
  2 require_once (__DIR__  .  ' / vendor/ autoload.php ' );
  3 
  4   =   array(
  5      "basePath"   =>   "https://api.aspose.cloud/v4.0" ,
  6      "authPath"   =>   "https://api.aspose.cloud/connect/token" ,
  7      "apiKey"   =>   "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" ,
  8      "appSID"   =>   "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" ,
  9      "defaultUserAgent"   =>   "Webkit" 
 10 
 11 
 12   =   new   HtmlApi($configuration);
 13 
 14   =   "FolderInStorage/test.svg" ;
 15   =   ' FolderInStorage/ test.gif ' ;
 16   =   null ;
 17 
 18 try   {
 19      $result  =   $api_html-> convertStorageToStorage($src,  $dst,  null ,  $options);
 20      print_r($result);
 21   catch   (Exception  $e)  {
 22      echo  ' Exception  when  calling  $api_html-> convertStorageToStorage:  ' ,  $e-> getMessage(),  PHP_EOL;
 23 
 24 ?> Ruby Das folgende Beispiel zeigt, wie man SVG in GIF  mithilfe der Ruby-Sprache konvertiert. Eine SVG-Datei wird aus dem Cloud-Speicher abgerufen, in GIF konvertiert und dann wieder im Cloud-Speicher gespeichert. Sie können das Ruby SDK aus dem
GitHub-Repository  herunterladen.
Copy  1 #   load  the  gem
  2   ' aspose_html_cloud' 
  3 
  4 #   Get  keys  from  aspose  site.
  5 #   There  is  free  quota  available. 
  6 #   For  more  details,  see  https://purchase.aspose.cloud/pricing 
  7 
  8 
  9   =   {
 10      "basePath" :"https://api.aspose.cloud/v4.0" ,
 11      "authPath" :"https://api.aspose.cloud/connect/token" ,
 12      "apiKey" :"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" ,
 13      "appSID" :"XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" ,
 14      "debug" :true 
 15 
 16 
 17   =   AsposeHtml::HtmlApi.new   CONFIG
 18 
 19   =   "FolderInStorage/test.svg"   #   String  |   Source  file.
 20   =   "FolderInStorage/test.gif"   #   String  |   Result  file.
 21   =   nil
 22 
 23 
 24    # Convert  the  file  from  the  storage  and  save  result  to  the  storage.
 25    result  =   api_instance.convert_storage_to_storage (src,  dst,  storage)
 26    p  result
 27   AsposeHtml::ApiError  =>   e
 28    puts  "Exception when calling api_instance.convert_storage_to_storage: #{e}" 
 29 Node.js Das folgende Beispiel zeigt, wie SVG in GIF  mithilfe der Node.js-Sprache konvertiert wird. Eine SVG-Datei wird aus dem Cloud-Speicher abgerufen, in GIF konvertiert und dann wieder im Cloud-Speicher gespeichert.
Copy  1 // Get keys from aspose site. 
  2 // There is free quota available. 
  3 // For more details, see https://purchase.aspose.cloud/pricing 
  4 	
  5 var   conf  =   {
  6      "basePath" :"https://api.aspose.cloud/v4.0" ,
  7      "authPath" :"https://api.aspose.cloud/connect/token" ,
  8      "apiKey" :"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" ,
  9      "appSID" :"XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" ,
 10      "defaultUserAgent" :"NodeJsWebkit" 
 11 
 12 
 13 var   api  =   require(' @asposecloud / aspose- html- cloud' );
 14 
 15 // Create Conversion Api object 
 16 var   conversionApi  =   new   api.ConversionApi (conf);
 17 
 18 var   src  =   "FolderInStorage/test.svg" ;  // {String} Source document. 
 19 var   dst  =   "FolderInStorage/test.gif" ;  // {String} Result document. 
 20 var   opts  =   null ;
 21 var   storage  =   null ;
 22 
 23 var   callback  =   function(error,  data,  response)  {
 24    if   (error)  {
 25      console.error (error);
 26    }  else   {
 27      console.log (data);
 28    }
 29 
 30 
 31 convertStorageToStorage (src,  dst,  storage,  opts,  callback);Swift Das folgende Beispiel zeigt, wie man mithilfe der Swift-Sprache SVG in GIF  konvertiert. Eine SVG-Datei wird aus dem Cloud-Speicher abgerufen, in GIF konvertiert und dann wieder im Cloud-Speicher gespeichert. Sie können das Swift SDK aus dem
GitHub-Repository  herunterladen.
Copy  1 import   Alamofire 
  2 import   Foundation 
  3 import   XCTest 
  4 import   AsposeHtmlCloud 
  5 
  6 setConfig (
  7 	 basePath:  "https://api.aspose.cloud/v4.0" ,
  8 	 authPath:  "https://api.aspose.cloud/connect/token" ,
  9 	 apiKey:  "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" ,
 10 	 appSID:  "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" ,
 11 	 debugging:  true 
 12 
 13 
 14   src  =   "FolderInStorage/test.svg" 
 15   dst  =   "FolderInStorage/test.gif" 
 16 
 17   expectation  =   self.expectation (description:  "testConvert to gif" )
 18 
 19 convertStorageToStorage (src:  src,  dst:  dst,  storage:  nil,  options:  nil)  {  (data,  error)  in
 20 
 21      guard  error  ==   nil  else   {
 22          XCTFail("Error convert SVG to gif. Error=\(error!.localizedDescription)" )
 23          return 
 24      }
 25 
 26      let  resultPath  =   data! .file ! 
 27 
 28      StorageAPI.objectExists (path:  resultPath,  storageName:  nil,  versionId:  nil)  {(data,  error)  in
 29          guard  error  ==   nil  else   {
 30              XCTFail("Error objectExists exist. Error=\(error!.localizedDescription)" )
 31              return 
 32          }
 33 
 34          XCTAssertTrue(data! .exists )
 35          XCTAssertFalse(data! .isFolder )
 36          expectation.fulfill ()
 37      }
 38 
 39 waitForExpectations (timeout:  100.0 ,  handler:  nil)Java/Android Das folgende Beispiel zeigt, wie man SVG in GIF  mit Java/Android konvertiert. Eine SVG-Datei wird aus dem Cloud-Speicher abgerufen, in GIF konvertiert und dann wieder im Cloud-Speicher gespeichert. Sie können das Java/Android SDK aus dem
GitHub-Repository  herunterladen.
Copy  1 Configuration.setBasePath ("https://api.aspose.cloud" );
   2 setAuthPath ("https://api.aspose.cloud/connect/token" );
  3 
  4   api  =   new   HtmlApi("CLIENT_ID" ,  "CLIENT_SECRET" );
  5 
  6   builder  =   new   ConverterBuilder()
  7                  .fromStorageFile ("input.svg" )
  8                  .saveToStorage ("output.gif" );
  9 
 10   result  =   api.convert (builder);CURL Das folgende Beispiel zeigt, wie man mithilfe der REST-API SVG in GIF  konvertiert. Eine SVG-Datei wird aus dem Cloud-Speicher abgerufen, in GIF konvertiert und dann wieder im Cloud-Speicher gespeichert.
Copy 1 curl  - X  POST  - v  \ 
  2 	 "https://api.aspose.cloud/v4.0/html/conversion/svg-gif"   \ 
 3      - d  "{'InputPath': '/test.svg', 'OutputFile': '/test.gif'}"   \ 
 4      - H  "Content-Type: application/json"   \ 
 5      - H  "Authorization:Bearer <JWT_token>" Siehe auch Der Artikel
Verfügbare SDKs  stellt Ihnen die Fähigkeit von Aspose.HTML Cloud vor, SDKs in verschiedenen Programmiersprachen wie C#, Java, Python, Ruby, PHP, Node.js, Swift, Android und C++ zu verwenden. Der Artikel
SDK-Konvertierungsoptionen  beschreibt eine Reihe von Klassen, die Optionen zum Konvertieren eines HTML-basierten Quelldokuments in PDF, XPS und Bild darstellen. Aspose.HTML Cloud API können Sie direkt von Ihrem Browser aus aufrufen, indem Sie auf die
API-Referenz  zugreifen. Sie können einen kostenlosen Online-
SVG-Konverter  ausprobieren, der SVG schnell und in hoher Qualität in ein Bild konvertiert. Laden Sie einfach Ihre Dateien hoch, konvertieren Sie sie und erhalten Sie das Ergebnis in wenigen Sekunden!