Cropper et redimensionner une image

Par wenz, il y a 11 ans


Bonjour ,
je suis entrain de faire une application, dans laquelle je souhaiterais cropper et redimensionner image. Quelqu'un pourrait m'expliquer la procédure à suivre?
Merci, et bien à vous.

5 réponses

FactureHero.com, il y a 11 ans

Voilà une fonction Php qui crop depuis le centre à la taille que tu veux :

//resize and crop image by center function resize_crop_image($max_width, $max_height, $source_file, $dst_dir, $quality = 80){ $imgsize = getimagesize($source_file); $width = $imgsize[0]; $height = $imgsize[1]; $mime = $imgsize['mime']; switch($mime){ case 'image/gif': $image_create = "imagecreatefromgif"; $image = "imagegif"; break; case 'image/png': $image_create = "imagecreatefrompng"; $image = "imagepng"; $quality = 7; break; case 'image/jpeg': $image_create = "imagecreatefromjpeg"; $image = "imagejpeg"; $quality = 80; break; default: return false; break; } $dst_img = imagecreatetruecolor($max_width, $max_height); $src_img = $image_create($source_file); $width_new = $height * $max_width / $max_height; $height_new = $width * $max_height / $max_width; //if the new width is greater than the actual width of the image, then the height is too large and the rest cut off, or vice versa if($width_new > $width){ //cut point by height $h_point = (($height - $height_new) / 2); //copy image imagecopyresampled($dst_img, $src_img, 0, 0, 0, $h_point, $max_width, $max_height, $width, $height_new); }else{ //cut point by width $w_point = (($width - $width_new) / 2); imagecopyresampled($dst_img, $src_img, 0, 0, $w_point, 0, $max_width, $max_height, $width_new, $height); } $image($dst_img, $dst_dir, $quality); if($dst_img)imagedestroy($dst_img); if($src_img)imagedestroy($src_img); } //exemple d'usage ensuite resize_crop_image(150, 150, tonimage.jpg, tonimage.jpg);
wenz, il y a 11 ans

Merci je vais essayer voir

wenz, il y a 11 ans

dit comment utiliser ça par rapport à la base img de cake <?php echo $this->image('nom-imga.jpg');?>
merci

Lartak, il y a 11 ans

dit comment utiliser ça par rapport à la base img de cake <?php echo $this->image('nom-imga.jpg');?>
merci

Regardes par exemple dans : Définitions des constantes du noyau.
Cela peut prendre un peu de temps, mais je conseille de lire au moins la doc de CakePHP, vous perdrez moins de temps par la suite pour coder vos applications, surtout qu'étant donné que la majeure partie en version française est traduite, pour ceux qui ne sont pas trop à l'aise (voir même pas du tout) avec l'anglais, ça facilite les choses.