ciao a tutti,
ho un piccolo problema con le librerie GD, creo la jpg ma mi viene prograssiva, come faccio a creare una jpg non progressiva?
Graze a tutti![]()
ciao a tutti,
ho un piccolo problema con le librerie GD, creo la jpg ma mi viene prograssiva, come faccio a creare una jpg non progressiva?
Graze a tutti![]()
Ti suggerisco di iniziare leggendo il manuale ufficiale:
http://www.php.net/imagejpeg
Note: If you want to output Progressive JPEGs, you need to ...
grazie mille, utilizzo questa classe
e leggendo la guida devo impostare imageinterlace() ma non riesco a capire quadno...Codice PHP:
<?PHP
class Image{
var $src_filename;
var $src_witdh;
var $src_height;
var $src_type;
var $src_attr;
var $src_image;
function Image($filename){
$this->src_filename = $filename;
$this->GetImageInfo();
}
function GetImageInfo(){
list($this->src_width,$this->src_height, $this->src_type, $this->src_attr) = getimagesize($this->src_filename);
}
function CreateSourceImage(){
switch($this->src_type){
case 1:
$this->src_image =imagecreatefromgif($this->src_filename);
break;
case 2:
$this->src_image =imagecreatefromjpeg($this->src_filename);
break;
case 3:
$this->src_image =imagecreatefrompng($this->src_filename);
break;
default: return false;
}
return true;
}
function SaveProportionateImage($filename, $quality, $height, $width){
$dest_height = $height;
$ratio = $this->src_height / $dest_height;
/*
IN PROPORZIONE
$dest_image = imagecreatetruecolor( $this->src_width / $ratio,$dest_height);
*/
$dest_image = imagecreatetruecolor($width, $height);
imagecopyresampled($dest_image, $this->src_image, 0, 0, 0, 0,
$this->src_width / $ratio,
$this->src_height / $ratio,
$this->src_width,
$this->src_height);
imagejpeg($dest_image, $filename.'.jpg', $quality);
imagedestroy($dest_image);
}
function Free(){
imagedestroy($this->src_image);
}
}
mi sapreste aiutare?
grazie ancora![]()
Ciao prova così:
case 2:
$this->src_image =imagecreatefromjpeg($this->src_filename);
$this->src_image = imageinterlace($this->src_image, true);
break;
Originariamente inviato da Rossella_75
grazie mille, utilizzo questa classe
e leggendo la guida devo impostare imageinterlace() ma non riesco a capire quadno...Codice PHP:
<?PHP
class Image{
var $src_filename;
var $src_witdh;
var $src_height;
var $src_type;
var $src_attr;
var $src_image;
function Image($filename){
$this->src_filename = $filename;
$this->GetImageInfo();
}
function GetImageInfo(){
list($this->src_width,$this->src_height, $this->src_type, $this->src_attr) = getimagesize($this->src_filename);
}
function CreateSourceImage(){
switch($this->src_type){
case 1:
$this->src_image =imagecreatefromgif($this->src_filename);
break;
case 2:
$this->src_image =imagecreatefromjpeg($this->src_filename);
break;
case 3:
$this->src_image =imagecreatefrompng($this->src_filename);
break;
default: return false;
}
return true;
}
function SaveProportionateImage($filename, $quality, $height, $width){
$dest_height = $height;
$ratio = $this->src_height / $dest_height;
/*
IN PROPORZIONE
$dest_image = imagecreatetruecolor( $this->src_width / $ratio,$dest_height);
*/
$dest_image = imagecreatetruecolor($width, $height);
imagecopyresampled($dest_image, $this->src_image, 0, 0, 0, 0,
$this->src_width / $ratio,
$this->src_height / $ratio,
$this->src_width,
$this->src_height);
imagejpeg($dest_image, $filename.'.jpg', $quality);
imagedestroy($dest_image);
}
function Free(){
imagedestroy($this->src_image);
}
}
mi sapreste aiutare?
grazie ancora![]()
ho fatto la prova ma l'immagine viene nera...
![]()
puoi postare anche lo script che utilizza la classe?
certo
grazie ancoraCodice PHP:
if($_POST['action'] == "carica"){
$new_name = "1";
if($new_name != ''){
// DA QUI INIZIO PER CARICARE L'IMMAGINE
if(!isset($_POST['Submit'])){
header("Location: index.php");
}else{
include_once 'config.php';
//faccio l'upload dell'img
include_once 'include/upload.class.php';
if(!isset($_FILES)) $_FILES = $HTTP_POST_FILES;
if(!isset($_SERVER)) $_FILES = $HTTP_POST_VARS;
$up = new FileUpload(TMP_DIR);
$up->RenameFile($_POST['new_name']);
$up->Upload($_FILES['file']);
//adesso ridimensiono l'img a 400 x 400
include_once 'include/image.class.php';
$img = new Image(TMP_DIR . '/' . $up->filename);
//creo l'immagine sorgente
$result = $img->CreateSourceImage();
//se il tipo di immagine supportato
//salvo 2 file:
//uno con l'img grande e uno con l'img piccola
//nelle rispettive directory
if($result){
//salvo l'immagine con altezza 400 lasciandola proporzionata
$img->SaveProportionateImage(IMAGE_DIR . '/' . $up->filename, IMAGE_QUALITY, IMAGE_HEIGHT, IMAGE_WIDTH);
//salvo l'immagine con altezza 75 lasciandola proporzionata
$img->SaveProportionateImage(THUMB_DIR . '/' . $up->filename, THUMB_QUALITY, THUMB_HEIGHT, THUMB_WIDTH);
//libero la memoria cancellando l'immagine sorgente
$img->Free();
}
//se il tipo di img non supportata
//o se il file uploadato nn un immagine
else
echo 'Immagine non valida
';
//In ogni caso cancello il file uploadato nella cartella ./tmp
$insertSQL = "INSERT INTO `xml` ( `id` , `path` , `description` , `thumbnail` , `link` , `id_gallery` ) VALUES (NULL , '$nome.jpg', '$descrizione', '$nome.jpg', '$link', '$cartella');";
mysql_query($insertSQL, $connessione) or die(mysql_error());
generaxml($connessione,$campo,'../images/'.$cartella.'/xml_'.$cartella.'.xml',$cartella);
$up->DeleteFile();
$stampa ='<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body onload="top.location.reload(true);self.close();">
</body>
</html>';
echo $stampa;
}
}else{
}
}
ok, prova così:
Codice PHP:
$this->src_image =imagecreatefromjpeg($this->src_filename);
$this->src_image = imageinterlace($this->src_filename, true);
sempre nero... non capisco!![]()
![]()
up![]()