forked from Skynet/discord-bot
feat: code borrowed from https://github.com/MCorange99/svg2colored-png/tree/main in order to convert from svg to png
This commit is contained in:
parent
725bfa41cc
commit
0034bd34d6
5 changed files with 867 additions and 221 deletions
|
@ -7,16 +7,19 @@ use serenity::{
|
|||
use skynet_discord_bot::common::database::{db_init, DataBase};
|
||||
use skynet_discord_bot::{get_config, Config};
|
||||
use std::{fs, process, sync::Arc};
|
||||
use std::ffi::OsStr;
|
||||
use std::fs::File;
|
||||
use std::io::Read;
|
||||
use std::path::PathBuf;
|
||||
use std::process::Command;
|
||||
use chrono::{Datelike, Utc};
|
||||
use gdk_pixbuf::PixbufLoader;
|
||||
use gdk_pixbuf::{Pixbuf, PixbufFormat, PixbufLoader};
|
||||
use gdk_pixbuf::prelude::PixbufLoaderExt;
|
||||
use resvg::usvg;
|
||||
use serde::Deserialize;
|
||||
use serenity::all::GuildId;
|
||||
use tokio::sync::RwLock;
|
||||
use skynet_discord_bot::common::renderer::{Args, Renderer};
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
|
@ -163,7 +166,7 @@ fn clone_repo(config: &Config, config_toml: &ConfigToml){
|
|||
.expect("failed to execute process");
|
||||
}
|
||||
|
||||
fn convert_svg_to_png(original: &str, out: &str){
|
||||
fn convert_svg_to_png(original: &PathBuf, out: &PathBuf){
|
||||
let mut f = File::open(original).unwrap();
|
||||
let mut buffer = Vec::new();
|
||||
// read the whole file
|
||||
|
@ -183,11 +186,41 @@ fn convert_svg_to_png(original: &str, out: &str){
|
|||
|
||||
fn get_logos(config: &Config, config_toml: &ConfigToml){
|
||||
let folder = format!("{}/open-governance/{}", &config.home, &config_toml.source.directory);
|
||||
|
||||
let folder_path = PathBuf::from(&folder);
|
||||
let paths = fs::read_dir(folder).unwrap();
|
||||
|
||||
let args = Args{
|
||||
input: folder_path.clone(),
|
||||
output: folder_path.clone(),
|
||||
colors: String::from(""),
|
||||
width: 1024,
|
||||
height: 1024,
|
||||
};
|
||||
let mut r = Renderer::new(&args).unwrap();
|
||||
|
||||
for path in paths {
|
||||
let tmp = path.unwrap();
|
||||
|
||||
let mut path_local = tmp.path().to_owned();
|
||||
match tmp.path().extension() {
|
||||
None => {}
|
||||
Some(ext) => {
|
||||
if ext == "svg" {
|
||||
let mut path_new = path_local.clone();
|
||||
path_new.set_extension("png");
|
||||
|
||||
// check if exists
|
||||
match r.render(&path_local, &args) {
|
||||
Ok(_) => log::info!("Successfully rendered all colors of {path_local:?}"),
|
||||
Err(e) => {
|
||||
log::error!("Failed to render {path_local:?}: {}", e)
|
||||
}
|
||||
}
|
||||
path_local = path_new;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
println!("Name: {}", &tmp.path().display());
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue