GithubHelp home page GithubHelp logo

Convert all files to PNG about affinity HOT 4 OPEN

ecceman avatar ecceman commented on August 21, 2024
Convert all files to PNG

from affinity.

Comments (4)

ycharbi avatar ycharbi commented on August 21, 2024 3

I made you a bash script to automate the task:

#!/bin/bash

if [ -n "${1}" ]
then
	if [ ! -d ${1} ]
	then
		echo "Directory not found."
		exit 1
	fi
else
	echo -e "You must provide the directory containing the Affinity SVGs.\nFor example: ./convertAffinitySvg.sh /home/toto/Downloads/affinity/svg"
	exit 1
fi

extention_src="svg"
extention_dst="png"
export_dpi=300
rep_affinity_src="${1}"
rep_affinity_dst="/tmp/affinity/${extention_dst}/"

cd ${rep_affinity_src}

creatRepDst()
{
for rep in $(find . -mindepth 1 -type d); do
	mkdir -p ${rep_affinity_dst}/${rep}
done
}

convertImg()
{
for convert in $(find . -mindepth 1 -name "*.${extention_src}"); do
	suppr_extension=${convert%.*}
	inkscape ${convert} -o ${rep_affinity_dst}/${suppr_extension}.${extention_dst} --export-type=${extention_dst} --export-dpi=${export_dpi}
done
}

creatRepDst
convertImg

You have to use it like this: ./convertAffinitySvg.sh ~/Downloads/affinity/svg

It creates a /tmp/affinity/png/ directory, creates the Affinity SVG tree and converts (by copying) the SVGs to PNG or any other format supported by Inkscape (svg,png,ps,eps,pdf,emf,wmf,xaml) by changing the value of the variable extension_dst (the created directory adapts to the extension).

I use Inkscape for conversion. There may be more optimized. I'll see...
If you have any questions, don't hesitate ;)

from affinity.

JulioPDX avatar JulioPDX commented on August 21, 2024 3

FYI, a bit late to the party. Also made a fork and python script for converting to PNG and size for the popular EVE-NG network simulation tool. https://github.com/JulioPDX/affinity/blob/master/convert.py

#!/usr/bin/env python

"""
Script used to convert a bunch of SVG files to PNG
"""

from os import walk, mkdir
import pyvips

# sudo apt-get install libvips
# pip install pyvips

PATH = "svg/"


def main():

    """
    All the action
    """

    for (root, dirs, files) in walk(PATH):
        for f in files:
            if ".svg" in f:
                try:
                    mkdir(path=f"{root}/png/")
                except OSError as error:
                    pass
                convert_file = pyvips.Image.thumbnail(f"{root}/{f}", 52, height=52)
                convert_file.write_to_file(f"{root}/png/{f.replace('svg', 'png')}")


if __name__ == "__main__":
    main()

from affinity.

dalcacer avatar dalcacer commented on August 21, 2024

@JulioPDX your useful script worked for me with cairosvg instead of pyvips. Thanks for that!

cairosvg.svg2png(url=f"{root}/{f}", write_to=f"{root}/png/{f.replace('svg', 'png')}")

from affinity.

JulioPDX avatar JulioPDX commented on August 21, 2024

@dalcacer Wow! I'm very happy I could be of help! I think I initially attempted with cairo but had some issue. Probably user error.

from affinity.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.