Petit nouveau ! |
3 Messages
06 mars 2012, 20:08
Voici tout le code:
<?php
session_start();
require_once 'include/config.php';
$fileName = UPLOAD_DIR.session_id().mt_rand(100000, 999999);
if($_POST['from'] == 'file'){
if($_FILES['file']['error'] == 0){
move_uploaded_file($_FILES['file']['tmp_name'], $fileName) or die('<script language="javascript" type="text/javascript">window.top.window.stopUpload({
result : 0,
msg : \'<div style="text-align: center" class="err">Cannot upload the file.</div>\'
});</script>');;
if( cartoonize($fileName, $_POST['effect']) )
die('<script language="javascript" type="text/javascript">window.top.window.stopUpload({
result : 1,
msg : \''.$fileName.'\'
});</script>');
else
die('<script language="javascript" type="text/javascript">window.top.window.stopUpload({
result : 0,
msg : \'<div style="text-align: center" class="err">Cannot process the image.</div>\'
});</script>');
}
if($_FILES['file']['error'] != 0 || $_FILES['file']['size'] > MAX_FILE_SIZE) {
die('<script language="javascript" type="text/javascript">window.top.window.stopUpload({
result : 0,
msg : \'<div style="text-align: center" class="err">Please select an Image to upload or please try with a smaller image.</div>\'
});</script>');
}
}
else{
$imgs = getimagesize($_POST['url']);
if( $imgs[0] == 0 )
die('0<div style="text-align: center" class="err">Cannot download the image.</div>');
file_put_contents($fileName, file_get_contents($_POST['url'])) or die('0<div style="text-align: center" class="err">Cannot download the image.</div>');
if( cartoonize($fileName, $_POST['effect']) )
die('1'.$fileName);
else
die('<div style="text-align: center" class="err">Cannot process the image.</div>');
}
function cartoonize($fileName, $effect){
list($width_orig, $height_orig) = getimagesize($fileName);
$real_max_width = REAL_MAX_WIDTH;
$real_max_height = REAL_MAX_HEIGHT;
if ($width_orig > $real_max_width || $height_orig > $real_max_height) {
$ratio_orig = $width_orig/ $height_orig;
if ($real_max_width / $real_max_height > $ratio_orig) {
$real_max_width = $real_max_height * $ratio_orig;
} else {
$real_max_height = $real_max_width / $ratio_orig;
}
}
else {
$real_max_width = $width_orig;
$real_max_height = $height_orig;
}
/* convert the image to cartoon */
$dx ="-1,0,1,-1,0,1,-1,0,1";
$dy ="1,1,1,0,0,0,-1,-1,-1";
system ($cmd = "/usr/local/bin/convert $fileName ".$fileName."tmpA1.tif");
unlink($fileName);
switch ( $effect) {
case 1:
system($cmd = "/usr/bin/tesseract ".$fileName."tmpA1.tif ".$fileName."-final.txt");
break;
case 2:
break;
case 3:
break;
case 4:
break;
case 5:
break;
default:
break;
}
return true;
}
?>
avec le logiciel gocr ce code fontionne bien
Merci