Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

414
Views
¿Cómo obtener, en la línea de comando, el cuadro delimitador de todo el contenido de un documento SVG?

Supongamos que nos dan un archivo SVG, digamos canvas1.svg . En mi caso, este archivo se habrá producido a partir de un PDF de una sola página utilizando pdf2svg .

Me gustaría tener un script bash (llamémoslo 'svgbb.sh') que tome el nombre del archivo SVG como argumento y devuelva como salida el cuadro delimitador de todo el contenido del archivo SVG, por ejemplo , x1, y1, x2 , y2, donde (x1, y1) son las coordenadas de la esquina superior izquierda del cuadro delimitador y (x2, y2) son las coordenadas de la esquina inferior derecha del cuadro delimitador.

Además, me gustaría que la solución fuera razonablemente rápida.

Sé cómo hacerlo usando Inkscape. Desafortunadamente, el script resultante es relativamente lento de ejecutar.

 #!/bin/bash filename="$1" # In Inkscape, the bounding box of all objects is called the *drawing*. # The coordinates of the drawing can be obtained by invoking inkscape on # the command line with the options `-X`, `-Y`, `-W`, and `-H` (which are # the abbreviations for `--query-x`, `--query-y`, `--query-width`, and # `--query-height`) # They can be all invoked at once. # Inkscape will return four numbers, in the units of px (normally 96 px=1 inch) # capture the output of the inkscape invocation and store it in an array a=(`inkscape -X -Y -W -H $filename`) x1=${a[0]} y1=${a[1]} w=${a[2]} h=${a[3]} # now we perform some simple arithmetic using the 'bc' tool x2=`echo $x1+$w | bc` y2=`echo $y1+$h | bc` # print the result echo $x1 $y1 $x2 $y2

Nuevamente, esto funciona, pero es bastante lento.

Por lo tanto, estoy buscando alternativas más rápidas, que no requieran la sobrecarga de Inkscape. El script puede usar cualquier herramienta gratuita y fácil de obtener que sea más apropiada: JavaScript (probablemente usando Node.js , pero tal vez no), python , C (o C++ , o...), etc., siempre que sea notablemente más rápido que la solución. con Inkscape que di arriba.

Estoy seguro de que esta respuesta basada en JavaScript podría adaptarse, pero casi no tengo experiencia con JavaScript, por lo que hacerlo por mi cuenta requeriría bastante inversión de tiempo.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!