IS
TImageCropper so aparece imagem apos F5
Bem fiz como abaixo o seguinte, carrego um imagem de qualquer origem e converto para PNG depois mudo de diretório, carrego o link no banco e no TImageCropper, na hora a imagem aparece, mas após salvar eu preciso sempre aperta o F5, ficando um bug do meu sistema feio. Alguém pode ajudar?
public function onSave( $param )
{
try
{
TTransaction::open('marca');
$this->form->validate();
$data = $this->form->getData();
$upfile = $data->imagecropper;
$path_parts = pathinfo($upfile);
$dir = "app/images/logo2.*";
foreach(glob($dir) as $file)
{
unlink($file);
}
if (($path_parts['filename']) && ($path_parts['filename'].'.'.$path_parts['extension']) != ('logo2.'.$path_parts['extension']) )
{
rename("tmp/".$path_parts['filename'].'.'.$path_parts['extension'], "app/images/logo2.".$path_parts['extension']);
$image = "app/images/logo2.".$path_parts['extension'];
switch (exif_imagetype($image)) {
case IMAGETYPE_PNG :
$img = imagecreatefrompng($image);
break;
case IMAGETYPE_GIF :
$img = imagecreatefromgif($image);
break;
case IMAGETYPE_JPEG :
$img = imagecreatefromjpeg($image);
break;
default :
throw new InvalidArgumentException('Invalid image type');
}
//$color = imagecolorallocatealpha($img,0x00,0x00,0x00,127);
//$color = = imagecolorallocate($image, 255, 255, 255);
//imageFill($img, 0, 0, $color);
$filename = "app/images/logo2.png";
imagepng($img, $filename);
$arquivo = "app/images/logo2.png";
if( file_exists($arquivo) )
{
$data->imagecropper = "app/images/logo2.png";
}
else
{
$data->imagecropper = "";
}
$arquivo = "app/images/logo2.jpg";
if( file_exists($arquivo) )
{
unlink($arquivo);
}
$arquivo = "app/images/logo2.gif";
if( file_exists($arquivo) )
{
unlink($arquivo);
}
}
$object = new Configuracao('images');
$object->fromArray( (array) $data);
$object->store();
$this->form->setData($data);
TTransaction::close();
new TMessage('info', TAdiantiCoreTranslator::translate('Record saved'));
$file = 'app/config/producao.ini';
if (!file_exists($file) OR is_writable($file))
{
//$designer->save($file);
//parent::openFile($file);
unlink($file);
$arquivo = fopen($file, "a");
fwrite($arquivo, "host = "$data->host"");
fwrite($arquivo, "nport = "$data->port"");
fwrite($arquivo, "nname = "$data->name"");
fwrite($arquivo, "nuser = "$data->user"");
fwrite($arquivo, "npass = "$data->pass"");
fwrite($arquivo, "ntype = "$data->type"");
fwrite($arquivo, "nprep = $data->prep");
}
else
{
throw new Exception(_t('Permission denied') . ': ' . $file);
}
$this->form->setData( $this->form->getData() );
}
catch (Exception $e)
{
new TMessage('error', $e->getMessage());
TTransaction::rollback();
}
}
public function onSave( $param )
{
try
{
TTransaction::open('marca');
$this->form->validate();
$data = $this->form->getData();
$upfile = $data->imagecropper;
$path_parts = pathinfo($upfile);
$dir = "app/images/logo2.*";
foreach(glob($dir) as $file)
{
unlink($file);
}
if (($path_parts['filename']) && ($path_parts['filename'].'.'.$path_parts['extension']) != ('logo2.'.$path_parts['extension']) )
{
rename("tmp/".$path_parts['filename'].'.'.$path_parts['extension'], "app/images/logo2.".$path_parts['extension']);
$image = "app/images/logo2.".$path_parts['extension'];
switch (exif_imagetype($image)) {
case IMAGETYPE_PNG :
$img = imagecreatefrompng($image);
break;
case IMAGETYPE_GIF :
$img = imagecreatefromgif($image);
break;
case IMAGETYPE_JPEG :
$img = imagecreatefromjpeg($image);
break;
default :
throw new InvalidArgumentException('Invalid image type');
}
//$color = imagecolorallocatealpha($img,0x00,0x00,0x00,127);
//$color = = imagecolorallocate($image, 255, 255, 255);
//imageFill($img, 0, 0, $color);
$filename = "app/images/logo2.png";
imagepng($img, $filename);
$arquivo = "app/images/logo2.png";
if( file_exists($arquivo) )
{
$data->imagecropper = "app/images/logo2.png";
}
else
{
$data->imagecropper = "";
}
$arquivo = "app/images/logo2.jpg";
if( file_exists($arquivo) )
{
unlink($arquivo);
}
$arquivo = "app/images/logo2.gif";
if( file_exists($arquivo) )
{
unlink($arquivo);
}
}
$object = new Configuracao('images');
$object->fromArray( (array) $data);
$object->store();
$this->form->setData($data);
TTransaction::close();
new TMessage('info', TAdiantiCoreTranslator::translate('Record saved'));
$file = 'app/config/producao.ini';
if (!file_exists($file) OR is_writable($file))
{
//$designer->save($file);
//parent::openFile($file);
unlink($file);
$arquivo = fopen($file, "a");
fwrite($arquivo, "host = "$data->host"");
fwrite($arquivo, "nport = "$data->port"");
fwrite($arquivo, "nname = "$data->name"");
fwrite($arquivo, "nuser = "$data->user"");
fwrite($arquivo, "npass = "$data->pass"");
fwrite($arquivo, "ntype = "$data->type"");
fwrite($arquivo, "nprep = $data->prep");
}
else
{
throw new Exception(_t('Permission denied') . ': ' . $file);
}
$this->form->setData( $this->form->getData() );
}
catch (Exception $e)
{
new TMessage('error', $e->getMessage());
TTransaction::rollback();
}
}