Streetview : test et validation

This commit is contained in:
Michael RICOIS 2016-02-08 10:22:43 +00:00
parent 9cfa1d586c
commit 43dd339c63
3 changed files with 21 additions and 12 deletions

View File

@ -4,17 +4,19 @@
<img id="streetview" data-cache="<?=$this->cache?>" data-saveas="<?=$this->saveas?>" src="<?=$this->url?>"
width="320" height="320" />
<script>
$('streetview').on('onload', function(e) {
$('img#streetview').on('load', function() {
var cache = $(this).data('cache');
var saveas = $(this).data('saveas');
if (cache == 0) {
var img = document.getElementById("streetview");
img.crossOrigin = "Anonymous";
var canvas = document.createElement("canvas");
canvas.width = $(this).width; canvas.height = $(this).height;
canvasContext = canvas.getContext("2d");
canvasContext.drawImage($(this), 0, 0, $(this).width, $(this).height);
var dataURL = canvas.toDataURL();
$.post(<?=$this->url(array('module'=>'file', 'controller'=>'streetview', 'action'=>'saveimg'),
'default', true)?>, { name: saveas, base64: dataURL });
canvas.width = img.width; canvas.height = img.height;
ctx = canvas.getContext("2d");
ctx.drawImage(img, 0, 0, img.width, img.height);
var dataURL = canvas.toDataURL('image/jpeg');
$.post('<?=$this->url(array('module'=>'file', 'controller'=>'streetview', 'action'=>'save'),'default', true)?>',
{ name: saveas, base64: dataURL });
}
});
</script>

View File

@ -11,7 +11,7 @@ class File_StreetviewController extends Zend_Controller_Action
{
$filename = $this->getRequest()->getParam('q');
$c = Zend_Registry::get('config');
$file = realpath($c->profil->path->data).'/google/streetview/'.$filename;
$file = realpath($c->profil->path->data).'/streetview/'.$filename;
$content_type = 'application/csv-tab-delimited-table';
//Envoi du fichier sur la sortie standard
@ -42,9 +42,16 @@ class File_StreetviewController extends Zend_Controller_Action
$request = $this->getRequest();
$name = $request->getParam('name');
$base64 = $request->getParam('base64');
$removePart = 'data:image/png;base64,';
$removePart = 'data:image/jpg;base64,';
$pos = strpos($base64, $removePart);
$data = substr($base64, $start + strlen($removePart));
file_put_contents(substr_replace($name.'.png','.jpg'), base64_decode($data));
$data = substr($base64, $pos + strlen($removePart));
$c = Zend_Registry::get('config');
$file = realpath($c->profil->path->data).'/streetview/'.$name;
$result = file_put_contents($file, base64_decode($data));
if ($result === false) {
echo "Error";
} else {
echo "";
}
}
}

View File

@ -118,7 +118,7 @@ class Scores_Google_Streetview
$this->siret = $siret;
$c = Zend_Registry::get('config');
$this->path = realpath($c->profil->path->data).'/google/streetview';
$this->path = realpath($c->profil->path->data).'/streetview';
}
/**