Sfoglia il codice sorgente

[Site] Image logos producteurs

feature/souke
Guillaume Bourgeois 10 mesi fa
parent
commit
f08faef01c
1 ha cambiato i file con 76 aggiunte e 0 eliminazioni
  1. +76
    -0
      frontend/controllers/SiteController.php

+ 76
- 0
frontend/controllers/SiteController.php Vedi File

@@ -548,4 +548,80 @@ class SiteController extends FrontendController
{
return $this->render('credit');
}

public function actionImageProducersLogos()
{
$image = @imagecreatetruecolor(1600, 1200);

// fond en blanc
$whiteBackground = imagecolorallocate($image, 255, 255, 255);
imagefill($image,0,0,$whiteBackground);

// logos des producteurs
$producerModule = $this->getProducerModule();
$producersArray = $producerModule->getRepository()->findProducersActive();
shuffle($producersArray);

$x = 50;
$y = 0;
foreach($producersArray as $producer) {
if($producer->logo) {
$logo = null;
$srcLogo = dirname(__FILE__).'/../../producer/web/uploads/'.$producer->logo;
$imageType = exif_imagetype($srcLogo);
if($imageType == IMAGETYPE_PNG) {
$logo = imagecreatefrompng($srcLogo);
$backgroundBlack = imagecolorallocate($logo , 0, 0, 0);
imagecolortransparent($logo, $backgroundBlack);
}
elseif($imageType == IMAGETYPE_JPEG) {
$logo = imagecreatefromjpeg($srcLogo);
}

if($logo) {
imagealphablending($logo, false);
imagesavealpha($logo, true);

list(
$sourceImageWidth,
$sourceImageHeight
) = getimagesize( $srcLogo);

if($sourceImageWidth && $sourceImageHeight) {
$targetImageWidth = 120;
$targetImageHeight = 120;

$sourceAspectRatio = $sourceImageWidth / $sourceImageHeight;
$targetAspectRatio = $targetImageWidth / $targetImageHeight;

if ($targetAspectRatio > $sourceAspectRatio) {
$targetImageHeight = (int) ($targetImageWidth / $sourceAspectRatio);
}
else {
$targetImageWidth = (int) ($targetImageHeight * $sourceAspectRatio);
}

$transparency = 0.7;
imagefilter($logo, IMG_FILTER_COLORIZE, 0,0,0,127 * $transparency);
imagecopyresampled($image, $logo, $x, $y + 60, 0, 0, $targetImageWidth, $targetImageHeight, $sourceImageWidth, $sourceImageHeight);

$x += $targetImageWidth + 75;
if($x > 1600) {
$x = rand(-50, 50);
$y += 200;
}
}
}
}
}

// noir et blanc
imagefilter($image, IMG_FILTER_GRAYSCALE);

// rendu de l'image
header ('Content-Type: image/png');
imagepng($image);
imagedestroy($image);
die();
}
}

Loading…
Annulla
Salva