Skip to content

Commit

Permalink
#7 add possibility to create logo directly on the server
Browse files Browse the repository at this point in the history
  • Loading branch information
btemperli committed Sep 1, 2022
1 parent 413200e commit 86032e5
Show file tree
Hide file tree
Showing 8 changed files with 867 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
node_modules
assets
csv
vendor

# PHP
admin/.env
Expand Down
6 changes: 6 additions & 0 deletions .htaccess
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,9 @@
deny from all
satisfy all
</Files>

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} \.svg$ [NC]
RewriteRule ^(.*)$ logo.php?name=$1 [L,QSA]
</IfModule>
76 changes: 76 additions & 0 deletions CsvHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

class CsvHelper
{
private $csv_filename_size = 'csv/svg_sizes.csv';
private $csv_separator = ';';

/**
* Constructor
*
* - prepare the used csv files
*/
public function __construct() {
$this->prepareCsvFile();
}

/**
* Prepare all the necessary CSV-Files at the beginning of saving all image entries.
*/
private function prepareCsvFile() {
if (!file_exists('csv')) {
mkdir('csv', 0755, true);
}

if (!file_exists($this->csv_filename_size)) {
$file = new SplFileObject($this->csv_filename_size, 'a');
$file->fputcsv(['name', 'width'], $this->csv_separator);
$file = null;
}
}

/**
* Search in CSV for a special $value.
*
* @param $file string filename & path of the csv file
* @param $value string search-value which should be found
* @param $position integer position of the value in the line-array
* @return array|false
* array: full csv line
* false: $value is not available.
*/
private function searchInCsv($file, $value, $position = 0) {
$fp = fopen($file, "r");
while (($record = fgetcsv($fp, null, $this->csv_separator)) !== false) {
if ($record && isset($record[$position])) {
if ($record[$position] == $value) {
return $record;
}
}
}
fclose($fp);
return false;
}

/**
* Get the size entry of the "$name" in our csv.
*
* @param $name
* @return array|false
*/
public function getSizeEntry($name) {
return $this->searchInCsv($this->csv_filename_size, $name);
}

/**
* Save a new size ($width) of the $name.
*
* @param $name
* @param $width
*/
public function saveSizeEntry($name, $width) {
$file = new SplFileObject($this->csv_filename_size, 'a');
$file->fputcsv([$name, $width], $this->csv_separator);
$file = null;
}
}
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,15 @@ Possible GET-Parameter:
- `claim-right`
- `color=[web|print|black]`

## Use it on your website
## Get directly the logo

You can get your logo directly from our website:

[https://logo.cevi.ch/logo.svg?left=LOGO&right=GENERATOR](https://logo.cevi.ch/logo.svg?left=LOGO&right=GENERATOR)

![https://logo.cevi.ch/logo.svg?left=LOGO&right=GENERATOR](https://logo.cevi.ch/logo.svg?left=LOGO&right=GENERATOR)

## Use the generator on your website

You can add the logo-generator to your website via an iframe:

Expand Down
6 changes: 6 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"require": {
"meyfa/php-svg": "^0.11.3",
"kartsims/easysvg": "^2.4"
}
}
118 changes: 118 additions & 0 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 86032e5

Please sign in to comment.