From a6e61492bcda52b7b5818b4a418bcf7a1800a88d Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Fri, 4 Mar 2011 13:54:47 +0000 Subject: [PATCH] Fix: reencoding preview tabs, Imagick is a class today --- htdocs/comm/propal/apercu.php | 56 ++++++++++------------------------- htdocs/lib/files.lib.php | 30 +++++++++++++++++++ 2 files changed, 46 insertions(+), 40 deletions(-) diff --git a/htdocs/comm/propal/apercu.php b/htdocs/comm/propal/apercu.php index 3cc29a7bc6c..7ef62f9bbab 100644 --- a/htdocs/comm/propal/apercu.php +++ b/htdocs/comm/propal/apercu.php @@ -166,48 +166,24 @@ if ($_GET["id"] > 0) { if (class_exists("Imagick")) { - $image=new Imagick(); - $image->readImage($file) ; - - /* - if ( imagick_iserror( $handle ) ) - { - $reason = imagick_failedreason( $handle ) ; - $description = imagick_faileddescription( $handle ) ; - - print "handle failed!
\nReason: $reason
\nDescription: $description
\n"; - } - */ - - $image->setImageFormat("PNG"); - - /* - if ( imagick_iserror( $handle ) ) - { - $reason = imagick_failedreason( $handle ) ; - $description = imagick_faileddescription( $handle ) ; - print "handle failed!
\nReason: $reason
\nDescription: $description
\n"; - } - */ - - $image->writeImage($file.".png"); - - } - else - { - $langs->load("other"); - print ''.$langs->trans("ErrorNoImagickReadimage").''; - } + $ret = dol_convert_file($file); + if ($ret < 0) $error++; + } + else + { + $langs->load("other"); + print ''.$langs->trans("ErrorNoImagickReadimage").''; } } - - print ""; - print ''; - - print ''.$langs->trans('AmountHT').''; - print ''.price($object->price).''; - print ''.$langs->trans("Currency".$conf->monnaie).''; - print ''; + } + + print ""; + print ''; + + print ''.$langs->trans('AmountHT').''; + print ''.price($object->price).''; + print ''.$langs->trans("Currency".$conf->monnaie).''; + print ''; } else { diff --git a/htdocs/lib/files.lib.php b/htdocs/lib/files.lib.php index 98a17c8e0bf..3afb3bec0f6 100644 --- a/htdocs/lib/files.lib.php +++ b/htdocs/lib/files.lib.php @@ -647,4 +647,34 @@ function dol_remove_file_process($filenb,$donotupdatesession=0) return $mesg; } +/** + * Convert file to image + */ +function dol_convert_file($file,$ext='png') +{ + global $langs; + + $image=new Imagick(); + $ret = $image->readImage($file); + if ($ret) + { + $ret = $image->setImageFormat($ext); + if ($ret) + { + $ret = $image->writeImage( $file . "." . $ext ); + if (! $ret) return -3; + } + else + { + return -2; + } + } + else + { + return -1; + } + + return 1; +} + ?>