1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
| function prevpost($txt, $pmess, $i, $bol) {
if (preg_match('/\[img=/', $txt)) {
$txt = strstr($txt, '[img=');
$pos = strpos($txt, ']');
$img[$i]=substr($txt, 5, $pos-5);
list($width, $height) = getimagesize($img[$i]);
if ($width>665){
$extension = substr( $img[$i], -3 );
$extension = strtolower( $extension );
switch ( $extension ) {
case "jpg":
case "peg":
$img_src_resource = imagecreatefromjpeg( $img[$i] );
break;
case "gif":
$img_src_resource = imagecreatefromgif( $img[$i]);
break;
case "png":
$img_src_resource = imagecreatefrompng( $img[$i] );
break;
case "bmp":
$img_src_resource = imagecreatefrombmp( $img[$i] );
break;
default:
echo "L'image n'est pas dans un format reconnu. Extensions autorisées : jpg/jpeg, gif, png, bmp";
break;
}
$new_width = 665;
$new_height = 665/$width * $height;
$img_dst_resource = imagecreatetruecolor($new_width, $new_height);
//$imge = imagecreatefromjpeg($img[$i]);
imagecopyresampled( $img_dst_resource, $img_src_resource, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
if ($bol=="1") {
if ($dh = opendir('pix/img')) {
$k=0;
while (($filea = readdir($dh)) !== false) {
if ($filea!= "." && $filea!= ".." && $filea!= "Thumbs.db"){
$k++;
}
}
}
switch ( $extension ) {
case "jpg":
case "peg":
$img_dst_chemin="pix/img/img$k.jpg";
imagejpeg( $img_dst_resource, $img_dst_chemin, 100 );
break;
case "gif":
$img_dst_chemin="pix/img/img$k.gif";
imagegif( $img_dst_resource, $img_dst_chemin, 100 );
break;
case "png":
$img_dst_chemin="pix/img/img$k.png";
imagepng( $img_dst_resource, $img_dst_chemin, 100 );
break;
case "bmp":
$img_dst_chemin="pix/img/img$k.bmp";
imagebmp( $img_dst_resource, $img_dst_chemin, 100 );
break;
}
} else {
if ($dh = opendir('pix/temp')) {
$k=0;
while (($filea = readdir($dh)) !== false) {
if ($filea!= "." && $filea!= ".." && $filea!= "Thumbs.db"){
$k++;
}
}
}
switch ( $extension ) {
case "jpg":
case "peg":
$img_dst_chemin="pix/temp/img$i.jpg";
imagejpeg( $img_dst_resource, $img_dst_chemin, 100 );
break;
case "gif":
$img_dst_chemin="pix/temp/img$i.gif";
imagegif( $img_dst_resource, $img_dst_chemin, 100 );
break;
case "png":
$img_dst_chemin="pix/temp/img$i.png";
imagepng( $img_dst_resource, $img_dst_chemin, 100 );
break;
case "bmp":
$img_dst_chemin="pix/temp/img$k.bmp";
imagebmp( $img_dst_resource, $img_dst_chemin, 100 );
break;
}
}
$pmess = str_replace($img[$i], $img_dst_chemin, $pmess);
}
if ($bol==1 && width<=665) {
if ($dh = opendir('pix/img')) {
$k=0;
while (($filea = readdir($dh)) !== false) {
if ($filea!= "." && $filea!= ".." && $filea!= "Thumbs.db"){
$k++;
}
}
}
switch ( $extension ) {
case "jpg":
case "peg":
$img_dst_chemin="pix/temp/img$k.jpg";
copy($img[$i], $img_dst_chemin);
break;
case "gif":
$img_dst_chemin="pix/temp/img$k.gif";
copy($img[$i], $img_dst_chemin);
break;
case "png":
$img_dst_chemin="pix/temp/img$k.png";
copy($img[$i], $img_dst_chemin);
break;
case "bmp":
$img_dst_chemin="pix/temp/img$k.bmp";
copy($img[$i], $img_dst_chemin);
break;
}
$pomess = str_replace($img[$i], $img_dst_chemin, $pmess);
}
$txt=substr($txt, $pos+1);
$i++;
prevpost($txt, $pmess, $i, $bol);
}
} |
Partager