Faker generates images with Imagine instead of using placeholder.it
This commit is contained in:
@@ -277,25 +277,6 @@ class Image extends BaseLoop
|
|||||||
}
|
}
|
||||||
|
|
||||||
return $loopResult;
|
return $loopResult;
|
||||||
/*
|
|
||||||
#PRODUIT : identifiant du produit associé (valué si le paramètre "produit" a été indiqué)
|
|
||||||
#PRODTITRE : titre du produit associé (valué si le paramètre "produit" a été indiqué)
|
|
||||||
#PRODREF : référence du produit associé (valué si le paramètre "produit" a été indiqué)
|
|
||||||
#RUBRIQUE : identifiant de la rubrique associée (valué si le paramètre "rubrique" a été indiqué)
|
|
||||||
#RUBTITRE : titre de la rubrique associée (valué si le paramètre "rubrique" a été indiqué)
|
|
||||||
#DOSSIER : identifiant du dossier associée (valué si le paramètre "dossier" a été indiqué)
|
|
||||||
#DOSTITRE : titre du dossier associée (valué si le paramètre "dossier" a été indiqué)
|
|
||||||
#CONTENU : identifiant du contenu associée (valué si le paramètre "contenu" a été indiqué)
|
|
||||||
#CONTTITRE : titre du contenu associée (valué si le paramètre "contenu" a été indiqué)
|
|
||||||
#IMAGE : URL de l'image transformée (redimensionnée, inversée, etc. suivant les paramètres d'entrée de la boucle).
|
|
||||||
#FICHIER : URL de l'image originale
|
|
||||||
#ID : identifiant de l'image
|
|
||||||
|
|
||||||
#TITRE : titre de l'image
|
|
||||||
#CHAPO : description courte de l'image
|
|
||||||
#DESCRIPTION : description longue de l'image
|
|
||||||
#COMPT : compteur débutant à 1. Utile pour l'utilisation de Javascript.
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
BIN
install/faker-assets/FreeSans.ttf
Normal file
BIN
install/faker-assets/FreeSans.ttf
Normal file
Binary file not shown.
@@ -4,6 +4,8 @@ use Propel\Runtime\Exception\PropelException;
|
|||||||
use Thelia\Model\CategoryImage;
|
use Thelia\Model\CategoryImage;
|
||||||
use Thelia\Model\FolderImage;
|
use Thelia\Model\FolderImage;
|
||||||
use Thelia\Model\ContentImage;
|
use Thelia\Model\ContentImage;
|
||||||
|
use Imagine\Image\Color;
|
||||||
|
use Imagine\Image\Point;
|
||||||
require __DIR__ . '/../core/bootstrap.php';
|
require __DIR__ . '/../core/bootstrap.php';
|
||||||
|
|
||||||
$thelia = new Thelia\Core\Thelia("dev", true);
|
$thelia = new Thelia\Core\Thelia("dev", true);
|
||||||
@@ -30,15 +32,38 @@ function generate_image($image, $position, $typeobj, $id) {
|
|||||||
;
|
;
|
||||||
|
|
||||||
// Generate images
|
// Generate images
|
||||||
$image_data = file_get_contents("http://placehold.it/320x200&text=Image+for+$typeobj+ID+".$id);
|
$imagine = new Imagine\Gd\Imagine();
|
||||||
|
$image = $imagine->create(new Imagine\Image\Box(320,240), new Color('#E9730F'));
|
||||||
|
|
||||||
|
$white = new Color('#FFF');
|
||||||
|
|
||||||
|
$font = $imagine->font(__DIR__.'/faker-assets/FreeSans.ttf', 14, $white);
|
||||||
|
|
||||||
|
$tbox = $font->box("THELIA");
|
||||||
|
$image->draw()->text("THELIA", $font, new Point((320 - $tbox->getWidth()) / 2, 30));
|
||||||
|
|
||||||
|
$str = sprintf("%s sample image", ucfirst($typeobj));
|
||||||
|
$tbox = $font->box($str);
|
||||||
|
$image->draw()->text($str, $font, new Point((320 - $tbox->getWidth()) / 2, 80));
|
||||||
|
|
||||||
|
$font = $imagine->font(__DIR__.'/faker-assets/FreeSans.ttf', 18, $white);
|
||||||
|
|
||||||
|
$str = sprintf("%s ID %d", strtoupper($typeobj), $id);
|
||||||
|
$tbox = $font->box($str);
|
||||||
|
$image->draw()->text($str, $font, new Point((320 - $tbox->getWidth()) / 2, 180));
|
||||||
|
|
||||||
|
$image->draw()
|
||||||
|
->line(new Point(0, 0), new Point(319, 0), $white)
|
||||||
|
->line(new Point(319, 0), new Point(319, 239), $white)
|
||||||
|
->line(new Point(319, 239), new Point(0,239), $white)
|
||||||
|
->line(new Point(0, 239), new Point(0, 0), $white)
|
||||||
|
;
|
||||||
|
|
||||||
$image_file = sprintf("%s/../local/media/images/%s/sample-image-%s.png", __DIR__, $typeobj, $id);
|
$image_file = sprintf("%s/../local/media/images/%s/sample-image-%s.png", __DIR__, $typeobj, $id);
|
||||||
|
|
||||||
if (! is_dir(dirname($image_file))) mkdir(dirname($image_file), 0777, true);
|
if (! is_dir(dirname($image_file))) mkdir(dirname($image_file), 0777, true);
|
||||||
|
|
||||||
if ($fh = fopen($image_file, "w")) {
|
$image->save($image_file);
|
||||||
fwrite($fh, $image_data);
|
|
||||||
fclose($fh);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user