has encountered a problem
We invite you to try again in a few minutes and if the problem persists contact us.
if ($maxWidth && $widthToUse > $maxWidth) { $ratio = $maxWidth / $widthToUse; $widthToUse = ceil($widthToUse * $ratio); $heightToUse = ceil($widthToUse * $ratio); } if ($maxHeight && $heightToUse > $maxHeight) { $ratio = $maxHeight / $heightToUse; $widthToUse = ceil($widthToUse * $ratio); $heightToUse = ceil($heightToUse * $ratio); } //echo $widthToUse." ".$heightToUse." ".($widthToUse*$heightToUse)." "; $image->scaleImage($widthToUse, $heightToUse, 1); } elseif (!$resize && ($maxWidth || $maxHeight)) { $currentWidth = $image->getImageWidth(); $currentHeight = $image->getImageHeight(); if ($maxWidth && $currentWidth > $maxWidth) { $ratio = $currentWidth / $maxWidth; $currentWidth = $maxWidth; $currentHeight = ceil($currentHeight / $ratio); } if ($maxHeight && $currentHeight > $maxHeight) { $ratio = $currentHeight / $maxHeight; $currentWidth = ceil($currentWidth / $ratio); $currentHeight = $maxHeight; } $image->scaleImage($currentWidth, $currentHeight, 1); } elseif ($resize && ($maxWidth || $maxHeight)) { $currentWidth = $image->getImageWidth(); $currentHeight = $image->getImageHeight(); if ($maxWidth && $currentWidth > $maxWidth) { $ratio = $currentWidth / $maxWidth; $currentWidth = $maxWidth; $currentHeight = ceil($currentHeight / $ratio); } if ($maxHeight && $currentHeight > $maxHeight) { $ratio = $currentHeight / $maxHeight; $currentWidth = ceil($currentWidth / $ratio); $currentHeight = $maxHeight; } $image->resizeImage($currentWidth, $currentHeight, \Imagick::FILTER_SINC, 0.9, false); } $maxWidth = $image->getImageWidth(); $maxHeight = $image->getImageHeight(); if ($rounded_corner) { if (!is_array($rounded_corner)) { $rounded_corner = [ 10, 10, ]; } $image->roundCorners($rounded_corner[0], $rounded_corner[1]); } if ($border) { $pixel->setColor($border[0]); $image->borderImage($pixel, $border[1], $border[2]); } if ($compositeImage && is_array($compositeImage) && count($compositeImage) == 3) { if (!($image2 = new \Imagick($compositeImage[0]))) { \Beeline::finishSpan(); return false; } $image->compositeImage($image2, \Imagick::COMPOSITE_DEFAULT, $compositeImage[1], $compositeImage[2]); } if ($txts) { if (!is_array($txts)) { $txts = [ [ $txts, ], ]; } elseif (!is_array($txts[0])) { $txts = [ $txts, ]; } foreach ($txts as $txt) { $draw = new \ImagickDraw(); $draw->setFont('Bookman-DemiItalic'); $draw->setFontSize(30); $txt_X = 10; $txt_Y = 10; $angle = 0; $pixel->setColor('white'); $msg = $txt[0]; $maxLines = 0; if (isset($txt[1])) { $txt_X = $txt[1]; } if (isset($txt[2])) { $txt_Y = $txt[2]; } if (isset($txt[3]) && $txt[3]) { $pixel->setColor($txt[3]); } if (isset($txt[4]) && $txt[4]) { $draw->setFontSize($txt[4]); } if (isset($txt[5]) && $txt[5]) { $draw->setFont($txt[5]); } if (isset($txt[6]) && $txt[6]) { $angle = $txt[6]; } if (isset($txt[7]) && $txt[7]) { $maxLines = $txt[7]; } $max_width = $maxWidth - $txt_X - 20; $draw->setFillColor($pixel); $words = explode(' ', $msg); $lines = []; $current_line = ''; $maxMetrics = 0; foreach ($words as $word) { if ($current_line == '') { $test = $word; } else { $test = "$current_line $word"; } $metrics = $image->queryFontMetrics($draw, $test); if ($metrics['textWidth'] > $max_width) { if ($maxLines && count($lines) + 1 == $maxLines) { $current_line .= ' ...'; break; } if ($current_line == '') { $lines[] = $test; $current_line = ''; } else { $lines[] = $current_line; $current_line = $word; } } else { if ($maxMetrics < $metrics['textWidth']) { $maxMetrics = $metrics['textWidth']; } $current_line = $test; } } if ($current_line != '') { $lines[] = $current_line; } $msg = implode("\n", $lines); if (!$txt_X) { $txt_X = ($maxWidth - $maxMetrics) / 2; } $image->annotateImage($draw, $txt_X, $txt_Y, $angle, $msg); //$destFilename .= implode('', $txt); } } $image->writeImage($path . $destFilename); // script ? envoie de mail par exemple ? $source = ''; if ($_SERVER['REQUEST_URI']) { $source .= $_SERVER['REQUEST_URI'] . "\n"; } else { $source .= $_SERVER['SCRIPT_FILENAME'] . "\n" . print_r($_SERVER['argv'], true); } $source .= $path0 . '/' . $srcFilename . "\n"; file_put_contents($path . $destFilename . '.source.txt', $source); } elseif (is_file($path . $destFilename)) { touch($path . $destFilename); } \Beeline::finishSpan(); if ($withpath) { return cleanPath('/' . \NA\Core\File::getTempImage()->urlRel . $destFilename); } return $destFilename; } catch (\Exception $e) { \Beeline::finishSpan(); return ($withpath ? \NA\Formatting::cleanPath(str_replace(LOCAL__WWW_DIR, '/', $path0)) : '') . $srcFilename; } } public static function getFramedPicture($path, $picture, $mask, $target_path = '../ressources/temp/') { $destination = $target_path . '_framed_' . $picture . '.png'; if (!class_exists('IMagick') || !file_exists($path . $picture)) { return; } /* ne pas regenerer l'image si elle existe */ if (file_exists($destination)) { return $destination; } /* récuperation du masque et ses dimentions */ $mask = new \IMagick($mask); $mask_w = $mask->getImageWidth(); $mask_h = $mask->getImageHeight(); /* récuperation de l'image a traiter */ $image = new \IMagick($path . $picture); /* mise à l'echel de l'image à l'echel du masque */ $image->resizeImage($mask_w, $mask_h, \Imagick::FILTER_LANCZOS, 1); /* application du masque , zones noirs = opcité 0 */ $image->setImageClipMask($mask); $image->setImageOpacity(0); /* le fichier généré est en png, il sera créé dans le dossier temporair passé en paramètre $target_path , * en cas de problème on affiche l'image par defaut (verifier si elle existe dans le dossier $path ) */ if ($image->writeImage($destination)) { return $destination; } else { return $path . 'image_default.png'; } } public function shadowImage($imagePath) { $imagick = new \Imagick(realpath($imagePath)); $imagick->shadowImage(0.4, 10, 50, 5); header('Content-Type: image/jpg'); echo $imagick->getImageBlob(); } public static function getModulatePicture($picture, $modulation = [100, 100, 100], $target_path = '../ressources/temp/') { if (!is_array($modulation)) { $modulation = intval($modulation); $modulation = ($modulation > 100 ? 100 : $modulation); $modulation = [$modulation, $modulation, $modulation]; } $name = basename($picture, mb_strrchr(basename($picture), '.')); $destination = $target_path . $name . '_modulation_' . implode('_', $modulation) . '.png'; if (file_exists($destination)) { return $destination; } if (!class_exists('IMagick') || !file_exists($picture)) { return; } $image = new \IMagick($picture); $image->modulateImage($modulation[0], $modulation[1], $modulation[2]); if ($image->writeImage($destination)) { return $destination; } return false; } public static function ImageCreateFromBMP2($filename) { $file = fopen($filename, 'rb'); $read = fread($file, 10); while (!feof($file) && $read != '') { $read .= fread($file, 1024); } $temp = unpack('H*', $read); $hex = $temp[1]; $header = mb_substr($hex, 0, 104); $body = str_split(mb_substr($hex, 108), 6); if (mb_substr($header, 0, 4) == '424d') { $header = mb_substr($header, 4); // Remove some stuff? $header = mb_substr($header, 32); // Get the width $width = hexdec(mb_substr($header, 0, 2)); // Remove some stuff? $header = mb_substr($header, 8); // Get the height $height = hexdec(mb_substr($header, 0, 2)); unset($header); } $x = 0; $y = 1; $image = imagecreatetruecolor($width, $height); foreach ($body as $rgb) { $r = hexdec(mb_substr($rgb, 4, 2)); $g = hexdec(mb_substr($rgb, 2, 2)); $b = hexdec(mb_substr($rgb, 0, 2)); $color = imagecolorallocate($image, $r, $g, $b); imagesetpixel($image, $x, $height - $y, $color); $x++; if ($x >= $width) { $x = 0; $y++; } } return $image; } public static function ImageCreateFromBMP($filename) { //Ouverture du fichier en mode binaire if (!$f1 = fopen($filename, 'rb')) { return false; } return false; //1 : Chargement des entêtes FICHIER $FILE = unpack('vfile_type/Vfile_size/Vreserved/Vbitmap_offset', fread($f1, 14)); if ($FILE['file_type'] != 19778) { return false; } //2 : Chargement des entêtes BMP $BMP = unpack( 'Vheader_size/Vwidth/Vheight/vplanes/vbits_per_pixel' . '/Vcompression/Vsize_bitmap/Vhoriz_resolution' . '/Vvert_resolution/Vcolors_used/Vcolors_important', fread($f1, 40) ); $BMP['colors'] = pow(2, $BMP['bits_per_pixel']); if ($BMP['size_bitmap'] == 0) { $BMP['size_bitmap'] = $FILE['file_size'] - $FILE['bitmap_offset']; } $BMP['bytes_per_pixel'] = $BMP['bits_per_pixel'] / 8; $BMP['bytes_per_pixel2'] = ceil($BMP['bytes_per_pixel']); $BMP['decal'] = ($BMP['width'] * $BMP['bytes_per_pixel'] / 4); $BMP['decal'] -= floor($BMP['width'] * $BMP['bytes_per_pixel'] / 4); $BMP['decal'] = 4 - (4 * $BMP['decal']); if ($BMP['decal'] == 4) { $BMP['decal'] = 0; } //3 : Chargement des couleurs de la palette $PALETTE = []; if ($BMP['colors'] < 16777216) { $PALETTE = unpack('V' . $BMP['colors'], fread($f1, $BMP['colors'] * 4)); } //4 : Création de l'image $IMG = fread($f1, $BMP['size_bitmap']); $VIDE = chr(0); $res = imagecreatetruecolor($BMP['width'], $BMP['height']); $P = 0; $Y = $BMP['height'] - 1; while ($Y >= 0) { $X = 0; while ($X < $BMP['width']) { if ($BMP['bits_per_pixel'] == 24) { $COLOR = unpack('V', mb_substr($IMG, $P, 3) . $VIDE); } elseif ($BMP['bits_per_pixel'] == 16) { $COLOR = unpack('n', mb_substr($IMG, $P, 2)); $COLOR[1] = $PALETTE[$COLOR[1] + 1]; } elseif ($BMP['bits_per_pixel'] == 8) { $COLOR = unpack('n', $VIDE . mb_substr($IMG, $P, 1)); $COLOR[1] = $PALETTE[$COLOR[1] + 1]; } elseif ($BMP['bits_per_pixel'] == 4) { $COLOR = unpack('n', $VIDE . mb_substr($IMG, floor($P), 1)); if (($P * 2) % 2 == 0) { $COLOR[1] = ($COLOR[1] >> 4); } else { $COLOR[1] = ($COLOR[1] & 0x0F); } $COLOR[1] = $PALETTE[$COLOR[1] + 1]; } elseif ($BMP['bits_per_pixel'] == 1) { $COLOR = unpack('n', $VIDE . mb_substr($IMG, floor($P), 1)); if (($P * 8) % 8 == 0) { $COLOR[1] = $COLOR[1] >> 7; } elseif (($P * 8) % 8 == 1) { $COLOR[1] = ($COLOR[1] & 0x40) >> 6; } elseif (($P * 8) % 8 == 2) { $COLOR[1] = ($COLOR[1] & 0x20) >> 5; } elseif (($P * 8) % 8 == 3) { $COLOR[1] = ($COLOR[1] & 0x10) >> 4; } elseif (($P * 8) % 8 == 4) { $COLOR[1] = ($COLOR[1] & 0x8) >> 3; } elseif (($P * 8) % 8 == 5) { $COLOR[1] = ($COLOR[1] & 0x4) >> 2; } elseif (($P * 8) % 8 == 6) { $COLOR[1] = ($COLOR[1] & 0x2) >> 1; } elseif (($P * 8) % 8 == 7) { $COLOR[1] = ($COLOR[1] & 0x1); } $COLOR[1] = $PALETTE[$COLOR[1] + 1]; } else { return false; } imagesetpixel($res, $X, $Y, $COLOR[1]); $X++; $P += $BMP['bytes_per_pixel']; } $Y--; $P += $BMP['decal']; } //Fermeture du fichier fclose($f1); return $res; } public static function open_image($file) { if (file_exists($file)) { $size = getimagesize($file); } if ($size) { switch ($size['mime']) { case 'image/jpeg': $im = imagecreatefromjpeg($file); //jpeg file break; case 'image/gif': $im = imagecreatefromgif($file); //gif file break; case 'image/png': $im = imagecreatefrompng($file); //png file break; case 'image/webp': $im = imagecreatefromwebp($file); //png file break; case 'image/bmp': case 'image/x-windows-bmp' : case 'image/x-ms-bmp' : $im = static::ImageCreateFromBMP($file); if (!$im) { $im = static::ImageCreateFromBMP2($file); } break; default: $im = false; break; } } return $im ? $im : false; } public static function recup_photos_au_hasard($id_rubrique, $limit = 3) { if (!$id_rubrique) { return false; } $sql = 'SELECT * FROM `db_diapo` WHERE id_rubrique = :id_rubrique AND valide=1 order by rand() ' . ($limit ? 'limit ' . \NPDO::limit($limit) : ''); if ($limit == 1) { return \NPDO::single_query($sql, ['id_rubrique' => $id_rubrique]); } else { return \NPDO::tab_query($sql, ['id_rubrique' => $id_rubrique]); } } public static function recup_diapo_colonne($id_rubrique, $colonne) { $sql_query = 'SELECT * FROM db_diapo WHERE id_rubrique = :id_rubrique AND valide =1 AND `Left`>0 GROUP BY `left` ORDER BY `left`'; $result = \NPDO::tab_query($sql_query, ['id_rubrique' => $id_rubrique]); $keys = @array_keys($result); $left = $result[$keys[$colonne]]['left']; if ($left != 0) { $sql_query = "Select * from db_diapo where id_rubrique= :id_rubrique and valide=1 and `left`='$left' order by top asc"; return \NPDO::tab_query($sql_query, ['id_rubrique' => $id_rubrique]); } else { return []; } } public static function recup_diapo_non_placer($id_rubrique) { $sql = "Select * from db_diapo where id_rubrique= :id_rubrique and valide=1 and `left`='0' and `top`='0' order by d_date asc"; return \NPDO::tab_query($sql, ['id_rubrique' => $id_rubrique]); } public function genere_melting_photos($id_rubrique) { if (!class_exists('ImagickPixel')) { return; } if (is_file(\NA\Core\File::getTempImage()->path . 'couv_mp_id_' . $id_rubrique . '.png')) { return; } if ($tab = recup_photos_au_hasard($id_rubrique)) { foreach ($tab as $photos) { $liste_photo[] = $photos; if (!is_file(PATH_ABS_DIAPORAMA . img0($photos['c_url_photo'])) && is_file(PATH_ABS_DIAPORAMA . $photos['c_url_photo'])) { // On resize $infos = @getimagesize(PATH_ABS_DIAPORAMA . $photos['c_url_photo']); $max_largeur = 120; ResizePicture(PATH_ABS_DIAPORAMA . $photos['c_url_photo'], PATH_ABS_DIAPORAMA . img0($photos['c_url_photo']), $max_largeur, $max_largeur * $infos[1] / $infos[0]); } } } else { return false; } // Création de l'image $color = new \ImagickPixel(); $color->setColor('rgb(255,255,255)'); $image = new \Imagick(REP_GLOBAL . '/images/spacer.gif'); $image->resizeImage(250, 200, \Imagick::FILTER_LANCZOS, 1); $image->setImageFormat('png'); // On ajoute les images dans l'image de base (mettre une boucle pour automatiser) if ($liste_photo[0]['c_url_photo'] && is_file(PATH_ABS_DIAPORAMA . img0($liste_photo[0]['c_url_photo']))) { $image2 = new \Imagick(PATH_ABS_DIAPORAMA . img0($liste_photo[0]['c_url_photo'])); $image2->resizeImage(100, 0, \Imagick::FILTER_LANCZOS, 1); $image2->borderImage($color, 8, 8); $image2->setImageFormat('png'); $image2->rotateImage(new \ImagickPixel('transparent'), 25); $image->compositeImage($image2, \Imagick::COMPOSITE_OVER, 70, 00); } if ($liste_photo[1]['c_url_photo'] && is_file(PATH_ABS_DIAPORAMA . img0($liste_photo[1]['c_url_photo']))) { $image4 = new \Imagick(PATH_ABS_DIAPORAMA . img0($liste_photo[1]['c_url_photo'])); $image4->resizeImage(100, 0, \Imagick::FILTER_LANCZOS, 1); $image4->borderImage($color, 8, 8); $image4->setImageFormat('png'); $image4->rotateImage(new \ImagickPixel('transparent'), -40); $image->compositeImage($image4, \Imagick::COMPOSITE_OVER, 0, 10); } if ($liste_photo[2]['c_url_photo'] && is_file(PATH_ABS_DIAPORAMA . img0($liste_photo[2]['c_url_photo']))) { $image3 = new \Imagick(PATH_ABS_DIAPORAMA . img0($liste_photo[2]['c_url_photo'])); $image3->resizeImage(100, 0, \Imagick::FILTER_LANCZOS, 1); $image3->borderImage($color, 8, 8); $image3->setImageFormat('png'); $image3->rotateImage(new \ImagickPixel('transparent'), 10); $image->compositeImage($image3, \Imagick::COMPOSITE_OVER, 50, 80); } // Ajout d'une ombre à l'image $shadow = $image->clone(); $shadow->setImageBackgroundColor(new \ImagickPixel('black')); $shadow->shadowImage(80, 3, 5, 5); $shadow->compositeImage($image, \Imagick::COMPOSITE_OVER, 0, 0); $shadow->writeImage(\NA\Core\File::getTempImage()->path . 'couv_mp_id_' . $id_rubrique . '.png'); $image->destroy(); } public static function getMaxDimToFit($img, $maxWidth, $maxHeight) { $info = getimagesize($img); $currentWidth = $info[0]; $currentHeight = $info[1]; $widthToUse = $currentWidth; $heightToUse = $currentHeight; if ($maxWidth && $widthToUse > $maxWidth) { $ratio = $widthToUse / $maxWidth; $widthToUse = ceil($widthToUse / $ratio); $heightToUse = ceil($heightToUse / $ratio); } if ($maxHeight && $heightToUse > $maxHeight) { $ratio = $heightToUse / $maxHeight; $widthToUse = ceil($widthToUse / $ratio); $heightToUse = ceil($heightToUse / $ratio); } return [$widthToUse, $heightToUse]; } public static function getCropedPicture($path, $picture, $startX, $startY, $width, $height, $target_path = '/temp/') { $destination = $target_path . '_' . $startX . $startY . $width . $height . '_croped_' . $picture . '.png'; if (!class_exists('IMagick') || !file_exists($path . $picture)) { return; } if (file_exists($destination)) { return $destination; } $image = new \Imagick(realpath($path . $picture)); $image->cropImage($width, $height, $startX, $startY); if ($image->writeImage(SITE_RESSOURCES . $destination)) { return $destination; } else { return false; } } } if ($maxWidth && $widthToUse > $maxWidth) { $ratio = $maxWidth / $widthToUse; $widthToUse = ceil($widthToUse * $ratio); $heightToUse = ceil($widthToUse * $ratio); } if ($maxHeight && $heightToUse > $maxHeight) { $ratio = $maxHeight / $heightToUse; $widthToUse = ceil($widthToUse * $ratio); $heightToUse = ceil($heightToUse * $ratio); } //echo $widthToUse." ".$heightToUse." ".($widthToUse*$heightToUse)." "; $image->scaleImage($widthToUse, $heightToUse, 1); } elseif (!$resize && ($maxWidth || $maxHeight)) { $currentWidth = $image->getImageWidth(); $currentHeight = $image->getImageHeight(); if ($maxWidth && $currentWidth > $maxWidth) { $ratio = $currentWidth / $maxWidth; $currentWidth = $maxWidth; $currentHeight = ceil($currentHeight / $ratio); } if ($maxHeight && $currentHeight > $maxHeight) { $ratio = $currentHeight / $maxHeight; $currentWidth = ceil($currentWidth / $ratio); $currentHeight = $maxHeight; } $image->scaleImage($currentWidth, $currentHeight, 1); } elseif ($resize && ($maxWidth || $maxHeight)) { $currentWidth = $image->getImageWidth(); $currentHeight = $image->getImageHeight(); if ($maxWidth && $currentWidth > $maxWidth) { $ratio = $currentWidth / $maxWidth; $currentWidth = $maxWidth; $currentHeight = ceil($currentHeight / $ratio); } if ($maxHeight && $currentHeight > $maxHeight) { $ratio = $currentHeight / $maxHeight; $currentWidth = ceil($currentWidth / $ratio); $currentHeight = $maxHeight; } $image->resizeImage($currentWidth, $currentHeight, \Imagick::FILTER_SINC, 0.9, false); } $maxWidth = $image->getImageWidth(); $maxHeight = $image->getImageHeight(); if ($rounded_corner) { if (!is_array($rounded_corner)) { $rounded_corner = [ 10, 10, ]; } $image->roundCorners($rounded_corner[0], $rounded_corner[1]); } if ($border) { $pixel->setColor($border[0]); $image->borderImage($pixel, $border[1], $border[2]); } if ($compositeImage && is_array($compositeImage) && count($compositeImage) == 3) { if (!($image2 = new \Imagick($compositeImage[0]))) { \Beeline::finishSpan(); return false; } $image->compositeImage($image2, \Imagick::COMPOSITE_DEFAULT, $compositeImage[1], $compositeImage[2]); } if ($txts) { if (!is_array($txts)) { $txts = [ [ $txts, ], ]; } elseif (!is_array($txts[0])) { $txts = [ $txts, ]; } foreach ($txts as $txt) { $draw = new \ImagickDraw(); $draw->setFont('Bookman-DemiItalic'); $draw->setFontSize(30); $txt_X = 10; $txt_Y = 10; $angle = 0; $pixel->setColor('white'); $msg = $txt[0]; $maxLines = 0; if (isset($txt[1])) { $txt_X = $txt[1]; } if (isset($txt[2])) { $txt_Y = $txt[2]; } if (isset($txt[3]) && $txt[3]) { $pixel->setColor($txt[3]); } if (isset($txt[4]) && $txt[4]) { $draw->setFontSize($txt[4]); } if (isset($txt[5]) && $txt[5]) { $draw->setFont($txt[5]); } if (isset($txt[6]) && $txt[6]) { $angle = $txt[6]; } if (isset($txt[7]) && $txt[7]) { $maxLines = $txt[7]; } $max_width = $maxWidth - $txt_X - 20; $draw->setFillColor($pixel); $words = explode(' ', $msg); $lines = []; $current_line = ''; $maxMetrics = 0; foreach ($words as $word) { if ($current_line == '') { $test = $word; } else { $test = "$current_line $word"; } $metrics = $image->queryFontMetrics($draw, $test); if ($metrics['textWidth'] > $max_width) { if ($maxLines && count($lines) + 1 == $maxLines) { $current_line .= ' ...'; break; } if ($current_line == '') { $lines[] = $test; $current_line = ''; } else { $lines[] = $current_line; $current_line = $word; } } else { if ($maxMetrics < $metrics['textWidth']) { $maxMetrics = $metrics['textWidth']; } $current_line = $test; } } if ($current_line != '') { $lines[] = $current_line; } $msg = implode("\n", $lines); if (!$txt_X) { $txt_X = ($maxWidth - $maxMetrics) / 2; } $image->annotateImage($draw, $txt_X, $txt_Y, $angle, $msg); //$destFilename .= implode('', $txt); } } $image->writeImage($path . $destFilename); // script ? envoie de mail par exemple ? $source = ''; if ($_SERVER['REQUEST_URI']) { $source .= $_SERVER['REQUEST_URI'] . "\n"; } else { $source .= $_SERVER['SCRIPT_FILENAME'] . "\n" . print_r($_SERVER['argv'], true); } $source .= $path0 . '/' . $srcFilename . "\n"; file_put_contents($path . $destFilename . '.source.txt', $source); } elseif (is_file($path . $destFilename)) { touch($path . $destFilename); } \Beeline::finishSpan(); if ($withpath) { return cleanPath('/' . \NA\Core\File::getTempImage()->urlRel . $destFilename); } return $destFilename; } catch (\Exception $e) { \Beeline::finishSpan(); return ($withpath ? \NA\Formatting::cleanPath(str_replace(LOCAL__WWW_DIR, '/', $path0)) : '') . $srcFilename; } } public static function getFramedPicture($path, $picture, $mask, $target_path = '../ressources/temp/') { $destination = $target_path . '_framed_' . $picture . '.png'; if (!class_exists('IMagick') || !file_exists($path . $picture)) { return; } /* ne pas regenerer l'image si elle existe */ if (file_exists($destination)) { return $destination; } /* récuperation du masque et ses dimentions */ $mask = new \IMagick($mask); $mask_w = $mask->getImageWidth(); $mask_h = $mask->getImageHeight(); /* récuperation de l'image a traiter */ $image = new \IMagick($path . $picture); /* mise à l'echel de l'image à l'echel du masque */ $image->resizeImage($mask_w, $mask_h, \Imagick::FILTER_LANCZOS, 1); /* application du masque , zones noirs = opcité 0 */ $image->setImageClipMask($mask); $image->setImageOpacity(0); /* le fichier généré est en png, il sera créé dans le dossier temporair passé en paramètre $target_path , * en cas de problème on affiche l'image par defaut (verifier si elle existe dans le dossier $path ) */ if ($image->writeImage($destination)) { return $destination; } else { return $path . 'image_default.png'; } } public function shadowImage($imagePath) { $imagick = new \Imagick(realpath($imagePath)); $imagick->shadowImage(0.4, 10, 50, 5); header('Content-Type: image/jpg'); echo $imagick->getImageBlob(); } public static function getModulatePicture($picture, $modulation = [100, 100, 100], $target_path = '../ressources/temp/') { if (!is_array($modulation)) { $modulation = intval($modulation); $modulation = ($modulation > 100 ? 100 : $modulation); $modulation = [$modulation, $modulation, $modulation]; } $name = basename($picture, mb_strrchr(basename($picture), '.')); $destination = $target_path . $name . '_modulation_' . implode('_', $modulation) . '.png'; if (file_exists($destination)) { return $destination; } if (!class_exists('IMagick') || !file_exists($picture)) { return; } $image = new \IMagick($picture); $image->modulateImage($modulation[0], $modulation[1], $modulation[2]); if ($image->writeImage($destination)) { return $destination; } return false; } public static function ImageCreateFromBMP2($filename) { $file = fopen($filename, 'rb'); $read = fread($file, 10); while (!feof($file) && $read != '') { $read .= fread($file, 1024); } $temp = unpack('H*', $read); $hex = $temp[1]; $header = mb_substr($hex, 0, 104); $body = str_split(mb_substr($hex, 108), 6); if (mb_substr($header, 0, 4) == '424d') { $header = mb_substr($header, 4); // Remove some stuff? $header = mb_substr($header, 32); // Get the width $width = hexdec(mb_substr($header, 0, 2)); // Remove some stuff? $header = mb_substr($header, 8); // Get the height $height = hexdec(mb_substr($header, 0, 2)); unset($header); } $x = 0; $y = 1; $image = imagecreatetruecolor($width, $height); foreach ($body as $rgb) { $r = hexdec(mb_substr($rgb, 4, 2)); $g = hexdec(mb_substr($rgb, 2, 2)); $b = hexdec(mb_substr($rgb, 0, 2)); $color = imagecolorallocate($image, $r, $g, $b); imagesetpixel($image, $x, $height - $y, $color); $x++; if ($x >= $width) { $x = 0; $y++; } } return $image; } public static function ImageCreateFromBMP($filename) { //Ouverture du fichier en mode binaire if (!$f1 = fopen($filename, 'rb')) { return false; } return false; //1 : Chargement des entêtes FICHIER $FILE = unpack('vfile_type/Vfile_size/Vreserved/Vbitmap_offset', fread($f1, 14)); if ($FILE['file_type'] != 19778) { return false; } //2 : Chargement des entêtes BMP $BMP = unpack( 'Vheader_size/Vwidth/Vheight/vplanes/vbits_per_pixel' . '/Vcompression/Vsize_bitmap/Vhoriz_resolution' . '/Vvert_resolution/Vcolors_used/Vcolors_important', fread($f1, 40) ); $BMP['colors'] = pow(2, $BMP['bits_per_pixel']); if ($BMP['size_bitmap'] == 0) { $BMP['size_bitmap'] = $FILE['file_size'] - $FILE['bitmap_offset']; } $BMP['bytes_per_pixel'] = $BMP['bits_per_pixel'] / 8; $BMP['bytes_per_pixel2'] = ceil($BMP['bytes_per_pixel']); $BMP['decal'] = ($BMP['width'] * $BMP['bytes_per_pixel'] / 4); $BMP['decal'] -= floor($BMP['width'] * $BMP['bytes_per_pixel'] / 4); $BMP['decal'] = 4 - (4 * $BMP['decal']); if ($BMP['decal'] == 4) { $BMP['decal'] = 0; } //3 : Chargement des couleurs de la palette $PALETTE = []; if ($BMP['colors'] < 16777216) { $PALETTE = unpack('V' . $BMP['colors'], fread($f1, $BMP['colors'] * 4)); } //4 : Création de l'image $IMG = fread($f1, $BMP['size_bitmap']); $VIDE = chr(0); $res = imagecreatetruecolor($BMP['width'], $BMP['height']); $P = 0; $Y = $BMP['height'] - 1; while ($Y >= 0) { $X = 0; while ($X < $BMP['width']) { if ($BMP['bits_per_pixel'] == 24) { $COLOR = unpack('V', mb_substr($IMG, $P, 3) . $VIDE); } elseif ($BMP['bits_per_pixel'] == 16) { $COLOR = unpack('n', mb_substr($IMG, $P, 2)); $COLOR[1] = $PALETTE[$COLOR[1] + 1]; } elseif ($BMP['bits_per_pixel'] == 8) { $COLOR = unpack('n', $VIDE . mb_substr($IMG, $P, 1)); $COLOR[1] = $PALETTE[$COLOR[1] + 1]; } elseif ($BMP['bits_per_pixel'] == 4) { $COLOR = unpack('n', $VIDE . mb_substr($IMG, floor($P), 1)); if (($P * 2) % 2 == 0) { $COLOR[1] = ($COLOR[1] >> 4); } else { $COLOR[1] = ($COLOR[1] & 0x0F); } $COLOR[1] = $PALETTE[$COLOR[1] + 1]; } elseif ($BMP['bits_per_pixel'] == 1) { $COLOR = unpack('n', $VIDE . mb_substr($IMG, floor($P), 1)); if (($P * 8) % 8 == 0) { $COLOR[1] = $COLOR[1] >> 7; } elseif (($P * 8) % 8 == 1) { $COLOR[1] = ($COLOR[1] & 0x40) >> 6; } elseif (($P * 8) % 8 == 2) { $COLOR[1] = ($COLOR[1] & 0x20) >> 5; } elseif (($P * 8) % 8 == 3) { $COLOR[1] = ($COLOR[1] & 0x10) >> 4; } elseif (($P * 8) % 8 == 4) { $COLOR[1] = ($COLOR[1] & 0x8) >> 3; } elseif (($P * 8) % 8 == 5) { $COLOR[1] = ($COLOR[1] & 0x4) >> 2; } elseif (($P * 8) % 8 == 6) { $COLOR[1] = ($COLOR[1] & 0x2) >> 1; } elseif (($P * 8) % 8 == 7) { $COLOR[1] = ($COLOR[1] & 0x1); } $COLOR[1] = $PALETTE[$COLOR[1] + 1]; } else { return false; } imagesetpixel($res, $X, $Y, $COLOR[1]); $X++; $P += $BMP['bytes_per_pixel']; } $Y--; $P += $BMP['decal']; } //Fermeture du fichier fclose($f1); return $res; } public static function open_image($file) { if (file_exists($file)) { $size = getimagesize($file); } if ($size) { switch ($size['mime']) { case 'image/jpeg': $im = imagecreatefromjpeg($file); //jpeg file break; case 'image/gif': $im = imagecreatefromgif($file); //gif file break; case 'image/png': $im = imagecreatefrompng($file); //png file break; case 'image/webp': $im = imagecreatefromwebp($file); //png file break; case 'image/bmp': case 'image/x-windows-bmp' : case 'image/x-ms-bmp' : $im = static::ImageCreateFromBMP($file); if (!$im) { $im = static::ImageCreateFromBMP2($file); } break; default: $im = false; break; } } return $im ? $im : false; } public static function recup_photos_au_hasard($id_rubrique, $limit = 3) { if (!$id_rubrique) { return false; } $sql = 'SELECT * FROM `db_diapo` WHERE id_rubrique = :id_rubrique AND valide=1 order by rand() ' . ($limit ? 'limit ' . \NPDO::limit($limit) : ''); if ($limit == 1) { return \NPDO::single_query($sql, ['id_rubrique' => $id_rubrique]); } else { return \NPDO::tab_query($sql, ['id_rubrique' => $id_rubrique]); } } public static function recup_diapo_colonne($id_rubrique, $colonne) { $sql_query = 'SELECT * FROM db_diapo WHERE id_rubrique = :id_rubrique AND valide =1 AND `Left`>0 GROUP BY `left` ORDER BY `left`'; $result = \NPDO::tab_query($sql_query, ['id_rubrique' => $id_rubrique]); $keys = @array_keys($result); $left = $result[$keys[$colonne]]['left']; if ($left != 0) { $sql_query = "Select * from db_diapo where id_rubrique= :id_rubrique and valide=1 and `left`='$left' order by top asc"; return \NPDO::tab_query($sql_query, ['id_rubrique' => $id_rubrique]); } else { return []; } } public static function recup_diapo_non_placer($id_rubrique) { $sql = "Select * from db_diapo where id_rubrique= :id_rubrique and valide=1 and `left`='0' and `top`='0' order by d_date asc"; return \NPDO::tab_query($sql, ['id_rubrique' => $id_rubrique]); } public function genere_melting_photos($id_rubrique) { if (!class_exists('ImagickPixel')) { return; } if (is_file(\NA\Core\File::getTempImage()->path . 'couv_mp_id_' . $id_rubrique . '.png')) { return; } if ($tab = recup_photos_au_hasard($id_rubrique)) { foreach ($tab as $photos) { $liste_photo[] = $photos; if (!is_file(PATH_ABS_DIAPORAMA . img0($photos['c_url_photo'])) && is_file(PATH_ABS_DIAPORAMA . $photos['c_url_photo'])) { // On resize $infos = @getimagesize(PATH_ABS_DIAPORAMA . $photos['c_url_photo']); $max_largeur = 120; ResizePicture(PATH_ABS_DIAPORAMA . $photos['c_url_photo'], PATH_ABS_DIAPORAMA . img0($photos['c_url_photo']), $max_largeur, $max_largeur * $infos[1] / $infos[0]); } } } else { return false; } // Création de l'image $color = new \ImagickPixel(); $color->setColor('rgb(255,255,255)'); $image = new \Imagick(REP_GLOBAL . '/images/spacer.gif'); $image->resizeImage(250, 200, \Imagick::FILTER_LANCZOS, 1); $image->setImageFormat('png'); // On ajoute les images dans l'image de base (mettre une boucle pour automatiser) if ($liste_photo[0]['c_url_photo'] && is_file(PATH_ABS_DIAPORAMA . img0($liste_photo[0]['c_url_photo']))) { $image2 = new \Imagick(PATH_ABS_DIAPORAMA . img0($liste_photo[0]['c_url_photo'])); $image2->resizeImage(100, 0, \Imagick::FILTER_LANCZOS, 1); $image2->borderImage($color, 8, 8); $image2->setImageFormat('png'); $image2->rotateImage(new \ImagickPixel('transparent'), 25); $image->compositeImage($image2, \Imagick::COMPOSITE_OVER, 70, 00); } if ($liste_photo[1]['c_url_photo'] && is_file(PATH_ABS_DIAPORAMA . img0($liste_photo[1]['c_url_photo']))) { $image4 = new \Imagick(PATH_ABS_DIAPORAMA . img0($liste_photo[1]['c_url_photo'])); $image4->resizeImage(100, 0, \Imagick::FILTER_LANCZOS, 1); $image4->borderImage($color, 8, 8); $image4->setImageFormat('png'); $image4->rotateImage(new \ImagickPixel('transparent'), -40); $image->compositeImage($image4, \Imagick::COMPOSITE_OVER, 0, 10); } if ($liste_photo[2]['c_url_photo'] && is_file(PATH_ABS_DIAPORAMA . img0($liste_photo[2]['c_url_photo']))) { $image3 = new \Imagick(PATH_ABS_DIAPORAMA . img0($liste_photo[2]['c_url_photo'])); $image3->resizeImage(100, 0, \Imagick::FILTER_LANCZOS, 1); $image3->borderImage($color, 8, 8); $image3->setImageFormat('png'); $image3->rotateImage(new \ImagickPixel('transparent'), 10); $image->compositeImage($image3, \Imagick::COMPOSITE_OVER, 50, 80); } // Ajout d'une ombre à l'image $shadow = $image->clone(); $shadow->setImageBackgroundColor(new \ImagickPixel('black')); $shadow->shadowImage(80, 3, 5, 5); $shadow->compositeImage($image, \Imagick::COMPOSITE_OVER, 0, 0); $shadow->writeImage(\NA\Core\File::getTempImage()->path . 'couv_mp_id_' . $id_rubrique . '.png'); $image->destroy(); } public static function getMaxDimToFit($img, $maxWidth, $maxHeight) { $info = getimagesize($img); $currentWidth = $info[0]; $currentHeight = $info[1]; $widthToUse = $currentWidth; $heightToUse = $currentHeight; if ($maxWidth && $widthToUse > $maxWidth) { $ratio = $widthToUse / $maxWidth; $widthToUse = ceil($widthToUse / $ratio); $heightToUse = ceil($heightToUse / $ratio); } if ($maxHeight && $heightToUse > $maxHeight) { $ratio = $heightToUse / $maxHeight; $widthToUse = ceil($widthToUse / $ratio); $heightToUse = ceil($heightToUse / $ratio); } return [$widthToUse, $heightToUse]; } public static function getCropedPicture($path, $picture, $startX, $startY, $width, $height, $target_path = '/temp/') { $destination = $target_path . '_' . $startX . $startY . $width . $height . '_croped_' . $picture . '.png'; if (!class_exists('IMagick') || !file_exists($path . $picture)) { return; } if (file_exists($destination)) { return $destination; } $image = new \Imagick(realpath($path . $picture)); $image->cropImage($width, $height, $startX, $startY); if ($image->writeImage(SITE_RESSOURCES . $destination)) { return $destination; } else { return false; } } }