Il est très facile de créer une vignette en tant que fichier, mais je ne peux pas comprendre comment utiliser les fonctions d'image PHP pour créer une image et stocker les données dans une variable que je peux utiliser pour stocker les données dans une table de base de données. Je suis nouveau dans les fonctions de l'image et je ne comprends pas leur fonctionnement. Sont-ils orientés annuaire? Donc, je dois créer quelque chose comme une carte tmp pour le fabricant de vignettes, puis utilisez simplement file_get_content, puis retirez l'image.créer une vignette pour blob avec php
Ou puis-je un peu comment stocker les données de l'image au cours du processus. Je n'ai aucune idée!
Voici comment je crée les vignettes si je dois les enregistrer dans un fichier:
//found at stackoverflow
function tumbmaker($updir, $img,$MaxWe=100,$MaxHe=150){
$arr_image_details = getimagesize($img);
$width = $arr_image_details[0];
$height = $arr_image_details[1];
$percent = 100;
if($width > $MaxWe) $percent = floor(($MaxWe * 100)/$width);
if(floor(($height * $percent)/100)>$MaxHe)
$percent = (($MaxHe * 100)/$height);
if($width > $height) {
$newWidth=$MaxWe;
$newHeight=round(($height*$percent)/100);
}else{
$newWidth=round(($width*$percent)/100);
$newHeight=$MaxHe;
}
if ($arr_image_details[2] == 1) {
$imgt = "ImageGIF";
$imgcreatefrom = "ImageCreateFromGIF";
}
if ($arr_image_details[2] == 2) {
$imgt = "ImageJPEG";
$imgcreatefrom = "ImageCreateFromJPEG";
}
if ($arr_image_details[2] == 3) {
$imgt = "ImagePNG";
$imgcreatefrom = "ImageCreateFromPNG";
}
if ($imgt) {
$old_image = $imgcreatefrom($img);
$new_image = imagecreatetruecolor($newWidth, $newHeight);
imagecopyresized($new_image, $old_image, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);
$imgt($new_image, $updir."_t.jpg");
return;
}
}
Je l'ai fait avec ce code:
function tumbmaker($img_source,$MaxWe=100,$MaxHe=150){
$arr_image_details = getimagesize($img_source);
$width = $arr_image_details[0];
$height = $arr_image_details[1];
$percent = 100;
if($width > $MaxWe) $percent = floor(($MaxWe * 100)/$width);
if(floor(($height * $percent)/100)>$MaxHe)
$percent = (($MaxHe * 100)/$height);
if($width > $height) {
$newWidth=$MaxWe;
$newHeight=round(($height*$percent)/100);
}else{
$newWidth=round(($width*$percent)/100);
$newHeight=$MaxHe;
}
if ($arr_image_details[2] == 1) {
$imgt = "ImageGIF";
$imgcreatefrom = "ImageCreateFromGIF";
}
if ($arr_image_details[2] == 2) {
$imgt = "ImageJPEG";
$imgcreatefrom = "ImageCreateFromJPEG";
}
if ($arr_image_details[2] == 3) {
$imgt = "ImagePNG";
$imgcreatefrom = "ImageCreateFromPNG";
}
if ($imgt) {
$old_image = $imgcreatefrom($img_source);
$new_image = imagecreatetruecolor($newWidth, $newHeight);
imagecopyresized($new_image, $old_image, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);
$imgt($new_image, $updir."_t.jpg");
ob_start();
$imgt($new_image);
$imgData = ob_get_clean();
return $imgData;
}
}
Lire la réponse pour plus d'informations
Et cela fonctionne très bien – botenvouwer