"); else { $width=ImageSX ($im); $height=ImageSY ($im); $preview_width=(int)($width*$preview_height/$height); $im_copy = @ImageCreate ($preview_width, $preview_height); // or die ("Cannot Initialize new GD image stream"); //$size[0], $size[1] imagecopyresized ($im_copy, $im, 0, 0,0, 0, $preview_width, $preview_height,$width, $height); $preview_name=makePreviewName($file_name); $proslo = saveImage($im_copy,$sklad,$koren,$aktualni,$preview_name); ImageDestroy($im_copy); ImageDestroy($im); if ($proslo) $vypis= "\r\n "; } return $vypis; } function imageCreateFromFilename($filename) { $pripona=substr($filename,strrpos($filename,".")+1); switch (strtolower ($pripona)) { case "gif": $im = @ImageCreateFromGIF ($filename); /* Attempt to open */ break; case "jpg": case "jpeg": $im = @ImageCreateFromJPEG ($filename); /* Attempt to open */ } return $im; } function makeLocalTempCopy($file_name) { $pripona=substr($file_name,strrpos($file_name,".")+1); $save_path=$save_path=GetUniqueTempFilename("ImagesDnld",$pripona); include ("define_extern.php"); $povedlo=ftp_dnld_file($extern_host,$extern_user,$extern_pass,$extern_path.$file_name,$save_path); return ($povedlo?$save_path:""); } function imageOpenUrl($sklad,$koren,$aktualni,$file_name) { switch ($sklad) { case "extern": $save_path=makeLocalTempCopy($aktualni.$file_name); $im=imageCreateFromFilename($save_path); unlink($save_path); break; case "implicit": $im=imageCreateFromFilename($koren.$aktualni.$file_name); //$extern_path ??? proc??? break; } return $im; } function imageDeleteUrl ($sklad,$koren,$aktualni,$file_name) { switch ($sklad) { case "extern": include ("define_extern.php"); $povedlo=ftp_delete_file($extern_host,$extern_user,$extern_pass,$extern_path.$aktualni.$file_name); break; case "implicit": $povedlo=unlink($koren.$aktualni.$file_name); break; } return $povedlo; } function imageRotateMy ($sklad,$koren,$aktualni,$file_name,$kam,$progress_) { global $progress; $progress->UpdateTask("opening","wait"); $im=imageOpenUrl($sklad,$koren,$aktualni,$file_name); $progress->UpdateTask("opening","OK"); if (!$im) /* See if it failed */ print "Chyba pri otevirani obrazku
"; else { $old_width=ImageSX($im);$old_height=ImageSY($im); $im_copy = @ImageCreate ($old_height, $old_width); print "($old_width, $old_height)"; if ($kam=="left") for ($x=0;$x<$old_width;$x++) { for ($y=0;$y<$old_height;$y++) ImageCopy ($im_copy, $im, $y, $old_width-$x, $x, $y, 1, 1); $progress->UpdateTask("rotate",round($x/$old_width*100)); } else for ($x=0;$x<$old_width;$x++) { for ($y=0;$y<$old_height;$y++) ImageCopy ($im_copy, $im, $old_height-$y, $x, $x, $y, 1, 1); $progress->UpdateTask("rotate",round($x/$old_width*100)); } $progress->UpdateTask("rotate","OK"); ImageDestroy($im); $progress->UpdateTask("saving","wait"); $povedlo = saveImage($im_copy,$sklad,$koren,$aktualni,$file_name); $progress->UpdateTask("saving","OK"); ImageDestroy($im_copy); } return $povedlo; } function GetUniqueTempFilename($predpona="",$pripona="") { srand((double)microtime()*1000000); $accessnum = uniqid(rand()); return "/tmp/$predpona".$accessnum.".".$pripona; } function saveImage($im_copy,$sklad,$koren,$aktualni,$file_name) { $pripona=substr($file_name,strrpos($file_name,".")+1); include ("define_extern.php"); switch ($sklad) { case "extern":$save_path=GetUniqueTempFilename("Images",$pripona);break; case "implicit": $save_path=$koren.$aktualni.$file_name;break; } $povedlo=ImageJPEG ($im_copy,$save_path); if ($povedlo) print "
Obrazek uspesne ulozen";else print"
Obrazek NEULOZEN!!!"; if ($sklad=="extern") { $povedlo&=ftp_upload_file($extern_host,$extern_user,$extern_pass,$save_path,$extern_path.$aktualni.$file_name); unlink($save_path); } if ($povedlo) print "
Obrazek uspesne presunut";else print"
Obrazek NEPRESUNUT!!!"; return $povedlo; } function makePreviewName($fname) { $tmp_tecka_pos=strrpos($fname,"."); return substr($fname,0,$tmp_tecka_pos)."_preview".substr($fname,$tmp_tecka_pos); } function GetImagePreviewWidth($radka,$mode="number") { if($radka->height>0&&$radka->width>0) $w=$radka->width/$radka->height*100; else $w=false; if ($w && $mode=="tag") $w="width='$w' height=100"; return $w; } function GetImageSizeTag($radka) { if($radka->height>0&&$radka->width>0) return "width='$radka->width' height='$radka->height'"; else return ""; } function ftp_upload_file($ftp_server,$ftp_user_name,$ftp_user_pass,$source_file,$destination_file) { $debug=false; print$conn_id = ftp_connect("$ftp_server"); $login_result = ftp_login($conn_id, "$ftp_user_name", "$ftp_user_pass"); // check connection if ((!$conn_id) || (!$login_result)) { echo "Ftp connection has failed!
";echo "Attempted to connect to $ftp_server for user $ftp_user_name
"; die; } else { if ($debug)echo "Connected to $ftp_server, for user $ftp_user_name
"; } // upload the file if ($debug)echo "Trying to put file '$source_file' on '$ftp_server', file '$destination_file'.
"; $upload = ftp_put($conn_id, "$destination_file", "$source_file", FTP_BINARY); // check upload status if (!$upload) { echo "Ftp upload has failed!
"; } else { if ($debug)echo "Uploaded $source_file to $ftp_server as $destination_file
"; } // close the FTP stream ftp_quit($conn_id); return $upload; } function ftp_dnld_file($ftp_server,$ftp_user_name,$ftp_user_pass,$source_file,$destination_file) { $conn_id = ftp_connect("$ftp_server"); $login_result = ftp_login($conn_id, "$ftp_user_name", "$ftp_user_pass"); // check connection if ((!$conn_id) || (!$login_result)) { echo "Ftp connection has failed!
Attempted to connect to $ftp_server for user $ftp_user_name
"; die; } else { if ($debug)echo "Connected to $ftp_server, for user $ftp_user_name
"; } // upload the file $upload = ftp_get($conn_id, "$destination_file", "$source_file", FTP_BINARY); // int ftp_get (int ftp_stream, string local_file, string remote_file, int mode) // check upload status if (!$upload) { echo "Ftp dnld has failed!
"; } else { if ($debug)echo "Downloaded $source_file to $ftp_server as $destination_file
"; } // close the FTP stream ftp_quit($conn_id); return $upload; } function ftp_delete_file($ftp_server,$ftp_user_name,$ftp_user_pass,$source_file) { $debug=false; $conn_id = ftp_connect("$ftp_server"); $login_result = ftp_login($conn_id, "$ftp_user_name", "$ftp_user_pass"); // check connection if ((!$conn_id) || (!$login_result)) { echo "Ftp connection has failed!
";echo "Attempted to connect to $ftp_server for user $ftp_user_name
"; die; } else { if ($debug)echo "Connected to $ftp_server, for user $ftp_user_name
"; } // delete the file $status = ftp_delete($conn_id, "$source_file"); // check the status if (!$status) { echo "Ftp delete has failed!
"; } else { if ($debug)echo "Deleted $source_file from $ftp_server
"; } // close the FTP stream ftp_quit($conn_id); return $status; } function ImageAdjustSvetlost($im,$value) { $im=ImageAdjustBarvy($im,$value,$value,$value); return $im; } function ImageAdjustBarvy($im,$red,$green,$blue) { for($i=0;$i255)$red_set=255; if($green_set>255)$green_set=255; if($blue_set>255)$blue_set=255; imagecolorset($im,$i,$red_set,$green_set,$blue_set); } return $im; } function ImageAdjustGamma($im,$gamma_id,$gamma_out) { $im=ImageGammaCorrect($im,$gamma_id,$gamma_out); return $im; } function ImageAdjustVyrez($im,$vyrez_x,$vyrez_y,$vyrez_w,$vyrez_h,$velikost_w, $velikost_h) { $im_copy = @ImageCreate ($velikost_w, $velikost_h); imagecopyresized ($im_copy, $im, 0, 0, $vyrez_x,$vyrez_y, $velikost_w, $velikost_h,$vyrez_w, $vyrez_h); //imagecopyresized (dst_im,src_im, dstX, dstY, srcX, srcY, dstW, dstH, srcW, srcH) // ImageDestroy($im); // return $im; return $im_copy; } function GetMyImageSize($sklad,$koren,$aktualni,$file_name) { if ($sklad=="implicit") { $size=GetImageSize($koren.$aktualni.$file_name); $sizeW=$size[0];$sizeH=$size[1]; } else { $im=imageOpenUrl($sklad,$koren,$aktualni,$file_name); $sizeW=ImageSX($im);$sizeH=ImageSY($im); } return array($sizeW,$sizeH); } function ImageAdjustKontrast($im,$red,$green,$blue) { $red_hist=array(255);$green_hist=array(255);$blue_hist=array(255); for($i=0;$i255)$red_set=255; if($green_set>255)$green_set=255; if($blue_set>255)$blue_set=255; imagecolorset($im,$i,$red_set,$green_set,$blue_set); } return $im; } function ImageAdjustAll($im,$vyrez,$vyrez_x,$vyrez_y,$vyrez_w,$vyrez_h, $velikost,$velikost_w,$velikost_h, $kontrast,$kontrast_value, $svetlost,$svetlost_value, $barvy,$barvy_r,$barvy_g,$barvy_b, $gamma,$gamma_in,$gamma_out) { global $progress; if ($vyrez=="true" || $velikost=="true") { $orig_w=ImageSX($im);$orig_h=ImageSY($im); // if (!isset($velikost_w)) $velikost_w=$size[0];if (!isset($velikost_h)) $velikost_h=$size[1]; if ($vyrez=="false") {$vyrez_x=$vyrez_y=0;$vyrez_w=$orig_w;$vyrez_h=$orig_h;} if ($velikost=="false") {$velikost_w=$vyrez_w;$velikost_h=$vyrez_h;} //print "$url"; $progress->UpdateTask("rozmery","wait"); $im=ImageAdjustVyrez($im,$vyrez_x,$vyrez_y,$vyrez_w,$vyrez_h,$velikost_w, $velikost_h); $progress->UpdateTask("rozmery","OK"); } if ($kontrast=="true") { $progress->UpdateTask("kontrast","wait"); $im=ImageAdjustKontrast($im,$kontrast_value); $progress->UpdateTask("kontrast","wait"); } if ($svetlost=="true" || $barvy=="true") { if (!isset($svetlost_value)) $svetlost_value=100; if (!isset($barvy_r)) $barvy_r=100;if (!isset($barvy_g)) $barvy_g=100;if (!isset($barvy_b)) $barvy_b=100; if($barvy=="false")$barvy_r=$barvy_g=$barvy_b=100; if($svetlost=="false")$svetlost_value=100; $progress->UpdateTask("svetlost","0"); $im=ImageAdjustSvetlost($im,$svetlost_value); $progress->UpdateTask("svetlost","50"); $im=ImageAdjustBarvy($im,$svetlost_value*$barvy_r/100,$svetlost_value*$barvy_g/100,$svetlost_value*$barvy_b/100); $progress->UpdateTask("svetlost","OK"); } if ($gamma=="true") { $progress->UpdateTask("gamma","wait"); $im=ImageAdjustGamma($im,$gamma_in,$gamma_out); $progress->UpdateTask("gamma","OK"); } $progress->closeWin(); return $im; } function GetNextID ($conn,$where,$radka) { return db_query_scalar($conn,"select id from imagebank where $where and ((datum='$radka->datum' and id>$radka->id) or datum>'$radka->datum') order by datum,id limit 1"); } function GetPrevID ($conn,$where,$radka) { return db_query_scalar($conn,"select id from imagebank where $where and ((datum='$radka->datum' and id<$radka->id) or datum<'$radka->datum') order by datum desc,id desc limit 1"); } ?>