salve a tutti ,
vorrei un consiglio aproposito della funzione php create thumbnail . Sto cercando di aggiungere la variabile percentuale per la creazione delle miniature ma non riesco assolutamente ad uscirne .
Il codice in questione è questo :
}
function _createThumbnail($fileName, $ext, $tw, $th, $newname, $thumbname) {
$mainimage = './uploads/'.$fileName.'.'.$ext;
$t = './uploads/'.$fileName.'_thumb'.'.'.$ext;
list($width, $height, $type, $attr) = getimagesize($mainimage);
$image_width = $width;
$image_height = $height;
$image_type = $type;
$scale = 0.3;
if($image_width > $image_height) {
$final_width = $tw;
$final_height = $th;
} elseif($image_width == $image_height) {
$final_width = $tw;
$final_height = $th;
} else {
$final_width = $tw;
$final_height = $th;
}
$x = $final_width/$image_width;
$y = $final_height/$image_height;
if($x < $y) {
$new_width = round($image_width *($final_height/$image_height));
$new_height = $final_height;
} else {
$new_height = round($image_height *($final_width/$image_width));
$new_width = $final_width;
}
$to_crop_left = ($new_width - ($final_width *$scale))/2;
$to_crop_top = ($new_height - ($final_height *$scale))/2;
$config['image_library'] = 'GD2';
$config['source_image'] = $mainimage;
$config['create_thumb'] = TRUE;
$config['maintain_ratio'] = true;
$config['master_dim'] = 'width';
$config['width'] = $new_width;
$config['height'] = $new_height;
$config['quality'] = '100%';
$this->load->library('image_lib', $config);
$this->image_lib->resize();
if(!$this->image_lib->resize()) echo $this->image_lib->display_errors();
$config['image_library'] = 'GD2';
$config['source_image'] = $t;
$config['create_thumb'] = FALSE;
$config['width'] = $final_width;
$config['height'] = $final_height;
$config['x_axis'] = $to_crop_left;
$config['y_axis'] = $to_crop_top;
$config['maintain_ratio'] = false;
$this->image_lib->initialize($config);
if(!$this->image_lib->crop()) {
echo $this->image_lib->display_errors();
} else {
$this->gallery_tbl->insertImage($_POST['id'], $newname, $thumbname);
}
}
function removeimage() {
$data['info'] = $this->gallery_tbl->particularImage($this->uri->segment(3));
$this->load->view('image_delete', $data);
}
function do_remove() {
$full = $this->gallery_tbl->imgToDelete($this->uri->segment(3));
$thumb = $this->gallery_tbl->thumbToDelete($this->uri->segment(3));
if(isset($full)) unlink('./uploads/'.$full);
if(isset($thumb)) unlink('./uploads/'.$thumb);
$this->gallery_tbl->deleteImage();
}
}
Aspetto una risposta e vi ringrazio in anticipo.
vorrei un consiglio aproposito della funzione php create thumbnail . Sto cercando di aggiungere la variabile percentuale per la creazione delle miniature ma non riesco assolutamente ad uscirne .
Il codice in questione è questo :
}
function _createThumbnail($fileName, $ext, $tw, $th, $newname, $thumbname) {
$mainimage = './uploads/'.$fileName.'.'.$ext;
$t = './uploads/'.$fileName.'_thumb'.'.'.$ext;
list($width, $height, $type, $attr) = getimagesize($mainimage);
$image_width = $width;
$image_height = $height;
$image_type = $type;
$scale = 0.3;
if($image_width > $image_height) {
$final_width = $tw;
$final_height = $th;
} elseif($image_width == $image_height) {
$final_width = $tw;
$final_height = $th;
} else {
$final_width = $tw;
$final_height = $th;
}
$x = $final_width/$image_width;
$y = $final_height/$image_height;
if($x < $y) {
$new_width = round($image_width *($final_height/$image_height));
$new_height = $final_height;
} else {
$new_height = round($image_height *($final_width/$image_width));
$new_width = $final_width;
}
$to_crop_left = ($new_width - ($final_width *$scale))/2;
$to_crop_top = ($new_height - ($final_height *$scale))/2;
$config['image_library'] = 'GD2';
$config['source_image'] = $mainimage;
$config['create_thumb'] = TRUE;
$config['maintain_ratio'] = true;
$config['master_dim'] = 'width';
$config['width'] = $new_width;
$config['height'] = $new_height;
$config['quality'] = '100%';
$this->load->library('image_lib', $config);
$this->image_lib->resize();
if(!$this->image_lib->resize()) echo $this->image_lib->display_errors();
$config['image_library'] = 'GD2';
$config['source_image'] = $t;
$config['create_thumb'] = FALSE;
$config['width'] = $final_width;
$config['height'] = $final_height;
$config['x_axis'] = $to_crop_left;
$config['y_axis'] = $to_crop_top;
$config['maintain_ratio'] = false;
$this->image_lib->initialize($config);
if(!$this->image_lib->crop()) {
echo $this->image_lib->display_errors();
} else {
$this->gallery_tbl->insertImage($_POST['id'], $newname, $thumbname);
}
}
function removeimage() {
$data['info'] = $this->gallery_tbl->particularImage($this->uri->segment(3));
$this->load->view('image_delete', $data);
}
function do_remove() {
$full = $this->gallery_tbl->imgToDelete($this->uri->segment(3));
$thumb = $this->gallery_tbl->thumbToDelete($this->uri->segment(3));
if(isset($full)) unlink('./uploads/'.$full);
if(isset($thumb)) unlink('./uploads/'.$thumb);
$this->gallery_tbl->deleteImage();
}
}
Aspetto una risposta e vi ringrazio in anticipo.