Skip to content
Extraits de code Groupes Projets
Valider 2d70f41c rédigé par ARNO*'s avatar ARNO*
Parcourir les fichiers

Rotation de l'image avec Convert et GD2

parent b2d3fe9b
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -369,8 +369,8 @@ function texte_upload_manuel($dir, $inclus = '') {
if ($ext == "zip") {
$texte_upload .= "\n<option value=\"$f\">&nbsp; &nbsp; &nbsp; &nbsp; $lefichier (en tant que fichier zip)</option>";
$texte_upload .= "\n<option value=\"$f--unzip\">&nbsp; &nbsp; &nbsp; &nbsp; $lefichier (d&eacute;compacter et installer les documents s&eacute;par&eacute;s)</option>";
$texte_upload .= "\n<option value=\"$f\">&nbsp; &nbsp; &nbsp; &nbsp; $lefichier (en tant que fichier zip)</option>";
$texte_upload .= "\n<option value=\"$f--unzip\">&nbsp; &nbsp; &nbsp; &nbsp; $lefichier (d&eacute;compacter et installer les documents s&eacute;par&eacute;s)</option>";
}
else if ($exts[$ext] == 'oui') $texte_upload .= "\n<option value=\"$f\">&nbsp; &nbsp; &nbsp; &nbsp; $lefichier</option>";
}
......@@ -381,9 +381,9 @@ function texte_upload_manuel($dir, $inclus = '') {
function texte_vignette_document($largeur_vignette, $hauteur_vignette, $fichier_vignette, $fichier_document) {
if ($largeur_vignette > 140) {
$rapport = 140.0 / $largeur_vignette;
$largeur_vignette = 140;
if ($largeur_vignette > 120) {
$rapport = 120.0 / $largeur_vignette;
$largeur_vignette = 120;
$hauteur_vignette = ceil($hauteur_vignette * $rapport);
}
if ($hauteur_vignette > 130) {
......@@ -550,39 +550,40 @@ function afficher_documents_non_inclus($id_article, $type = "article", $flag_mod
echo "<div style='text-align: center;'><a href='../$fichier'><img src='$fichier_vignette' border='0'></a></div>";
}
$process = lire_meta('image_process');
// imagick (php4-imagemagick)
if ($process == 'imagick') {
echo "<div class='verdana1' style='text-align:center'>";
$link_rot = $image_link;
$link_rot->addVar('redirect', $redirect_url);
$link_rot->addVar('hash', calculer_action_auteur("rotate ".$id_document));
$link_rot->addVar('hash_id_auteur', $connect_id_auteur);
$link_rot->addVar('doc_rotate', $id_document);
$link_rot->addVar('vignette_aff', $id_document);
$link_rot->addVar('var_rot', -90);
echo "<a href='".$link_rot->getUrl("portfolio")."'>gauche</a> |";
$link_rot = $image_link;
$link_rot->addVar('redirect', $redirect_url);
$link_rot->addVar('hash', calculer_action_auteur("rotate ".$id_document));
$link_rot->addVar('hash_id_auteur', $connect_id_auteur);
$link_rot->addVar('doc_rotate', $id_document);
$link_rot->addVar('vignette_aff', $id_document);
$link_rot->addVar('var_rot', 90);
echo "<a href='".$link_rot->getUrl("portfolio")."'>droite</a> |";
$link_rot = $image_link;
$link_rot->addVar('redirect', $redirect_url);
$link_rot->addVar('hash', calculer_action_auteur("rotate ".$id_document));
$link_rot->addVar('hash_id_auteur', $connect_id_auteur);
$link_rot->addVar('doc_rotate', $id_document);
$link_rot->addVar('vignette_aff', $id_document);
$link_rot->addVar('var_rot', 180);
echo "<a href='".$link_rot->getUrl("portfolio")."'>180&deg;</a>";
if ($flag_modif) {
$process = lire_meta('image_process');
// imagick (php4-imagemagick)
if ($process == 'imagick' OR $process == 'gd2' OR $process == 'convert') {
echo "<div class='verdana1' style='text-align:center'>";
$link_rot = $image_link;
$link_rot->addVar('redirect', $redirect_url);
$link_rot->addVar('hash', calculer_action_auteur("rotate ".$id_document));
$link_rot->addVar('hash_id_auteur', $connect_id_auteur);
$link_rot->addVar('doc_rotate', $id_document);
$link_rot->addVar('vignette_aff', $id_document);
$link_rot->addVar('var_rot', -90);
echo "<a href='".$link_rot->getUrl("portfolio")."'>gauche</a> |";
$link_rot = $image_link;
$link_rot->addVar('redirect', $redirect_url);
$link_rot->addVar('hash', calculer_action_auteur("rotate ".$id_document));
$link_rot->addVar('hash_id_auteur', $connect_id_auteur);
$link_rot->addVar('doc_rotate', $id_document);
$link_rot->addVar('vignette_aff', $id_document);
$link_rot->addVar('var_rot', 90);
echo "<a href='".$link_rot->getUrl("portfolio")."'>droite</a> |";
$link_rot = $image_link;
$link_rot->addVar('redirect', $redirect_url);
$link_rot->addVar('hash', calculer_action_auteur("rotate ".$id_document));
$link_rot->addVar('hash_id_auteur', $connect_id_auteur);
$link_rot->addVar('doc_rotate', $id_document);
$link_rot->addVar('vignette_aff', $id_document);
$link_rot->addVar('var_rot', 180);
echo "<a href='".$link_rot->getUrl("portfolio")."'>180&deg;</a>";
}
}
if ($flag_modif) {
if ($flag_deplier) $triangle = bouton_block_visible("port$id_document");
else $triangle = bouton_block_invisible("port$id_document");
......
......@@ -371,6 +371,60 @@ if ($image_supp) {
// Faire tourner une image
//
//$imagePath - path to your image; function will save rotated image overwriting the old one
//$rtt - should be 90 or -90 - cw/ccw
function gdRotate($imagePath,$rtt){
if(preg_match("/\.(png)/i", $imagePath)) $src_img=ImageCreateFromPNG($imagePath);
elseif(preg_match("/\.(jpg)/i", $imagePath)) $src_img=ImageCreateFromJPEG($imagePath);
elseif(preg_match("/\.(bmp)/i", $imagePath)) $src_img=ImageCreateFromWBMP($imagePath);
$size=GetImageSize($imagePath);
//note: to make it work on GD 2.xx properly change ImageCreate to ImageCreateTrueColor
$process = lire_meta('image_process');
if ($process == "gd2") $dst_img=ImageCreateTrueColor($size[1],$size[0]);
else $dst_img=ImageCreate($size[1],$size[0]);
if($rtt==90){
$t=0;
$b=$size[1]-1;
while($t<=$b){
$l=0;
$r=$size[0]-1;
while($l<=$r){
imagecopy($dst_img,$src_img,$t,$r,$r,$b,1,1);
imagecopy($dst_img,$src_img,$t,$l,$l,$b,1,1);
imagecopy($dst_img,$src_img,$b,$r,$r,$t,1,1);
imagecopy($dst_img,$src_img,$b,$l,$l,$t,1,1);
$l++;
$r--;
}
$t++;
$b--;
}
}
elseif($rtt==-90){
$t=0;
$b=$size[1]-1;
while($t<=$b){
$l=0;
$r=$size[0]-1;
while($l<=$r){
imagecopy($dst_img,$src_img,$t,$l,$r,$t,1,1);
imagecopy($dst_img,$src_img,$t,$r,$l,$t,1,1);
imagecopy($dst_img,$src_img,$b,$l,$r,$b,1,1);
imagecopy($dst_img,$src_img,$b,$r,$l,$b,1,1);
$l++;
$r--;
}
$t++;
$b--;
}
}
ImageDestroy($src_img);
ImageInterlace($dst_img,0);
ImageJPEG($dst_img,$imagePath);
}
if ($doc_rotate) {
// Securite
if (!verifier_action_auteur("rotate $doc_rotate", $hash, $hash_id_auteur)) {
......@@ -393,6 +447,18 @@ if ($doc_rotate) {
imagick_write($handle, $image);
if (!@file_exists($image)) return; // echec imagick
}
else if ($process == "gd2") { // theoriquement compatible gd1, mais trop forte degradation d'image
if ($var_rot == 180) { // 180 = 90+90
gdRotate ($image, 90);
gdRotate ($image, 90);
} else {
gdRotate ($image, $var_rot);
}
}
else if ($process = "convert") {
$commande = "$convert_command -rotate $var_rot $image $image";
exec($commande);
}
$size_image = @getimagesize($image);
$largeur = $size_image[0];
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter