2010-11-17 21 views
66

Mój hosting powiedział, że ImageMagic został preinstalowany na serwerze. Zrobiłem szybkie wyszukiwanie "ImageMagick" w wyjściu phpinfo() i nic nie znalazłem. Nie mogę SSH na serwerze, więc czy jest jakiś sposób w PHP mogę zweryfikować instalację?Weryfikacja instalacji ImageMagick

Odpowiedz

42

Spróbuj tego:

<?php 
//This function prints a text array as an html list. 
function alist ($array) { 
    $alist = "<ul>"; 
    for ($i = 0; $i < sizeof($array); $i++) { 
    $alist .= "<li>$array[$i]"; 
    } 
    $alist .= "</ul>"; 
    return $alist; 
} 
//Try to get ImageMagick "convert" program version number. 
exec("convert -version", $out, $rcode); 
//Print the return code: 0 if OK, nonzero if error. 
echo "Version return code is $rcode <br>"; 
//Print the output of "convert -version"  
echo alist($out); 
?> 
+14

to testy, jeśli jest zainstalowana aplikacja ImageMagick, a nie Moduł PHP – stillstanding

+0

Kod powrotu wersji to 0 * Wersja: ImageMagick 6.3.7 08/09/09 Q16 http://www.imagemagick.org * Prawa autorskie: Copyright (C) 1999-2008 ImageMagick Studio LLC –

+0

to właśnie strona powraca. Wygląda na to, że ma problem z przywróceniem wersji, ale w jakiś sposób zwraca informacje o prawach autorskich. –

15

Można łatwo sprawdzić dla klasy Imagick w PHP.

if(class_exists("Imagick")) 
{ 
    //Imagick is installed 
} 
+7

** important: ** Czasami to zwraca FALSE, ale 'extension_loaded ('imagick')' zwraca TRUE!, więc myślę, że lepiej jest: 'if (extension_loaded ('imagick') || class_exists (" Imagick ")) {/ * do Imagick * /}' –

112
if (!extension_loaded('imagick')) 
    echo 'imagick not installed'; 
7

Spróbuj jednorazowe rozwiązanie, które powinny dowiedzieć się, gdzie ImageMagick jest, jeśli masz do niego dostęp ...

Znalazło to wszystkie wersje na moim GoDaddy hostingu.

Prześlij ten plik na swój serwer i nazwij go ImageMagick.php lub coś, a następnie uruchom go. Otrzymasz wszystkie potrzebne informacje ... mam nadzieję ...

Powodzenia.

<? 
/* 
// This file will run a test on your server to determine the location and versions of ImageMagick. 
//It will look in the most commonly found locations. The last two are where most popular hosts (including "Godaddy") install ImageMagick. 
// 
// Upload this script to your server and run it for a breakdown of where ImageMagick is. 
// 
*/ 
echo '<h2>Test for versions and locations of ImageMagick</h2>'; 
echo '<b>Path: </b> convert<br>'; 

function alist ($array) { //This function prints a text array as an html list. 
    $alist = "<ul>"; 
    for ($i = 0; $i < sizeof($array); $i++) { 
     $alist .= "<li>$array[$i]"; 
    } 
    $alist .= "</ul>"; 
    return $alist; 
} 

exec("convert -version", $out, $rcode); //Try to get ImageMagick "convert" program version number. 
echo "Version return code is $rcode <br>"; //Print the return code: 0 if OK, nonzero if error. 
echo alist($out); //Print the output of "convert -version" 
echo '<br>'; 
echo '<b>This should test for ImageMagick version 5.x</b><br>'; 
echo '<b>Path: </b> /usr/bin/convert<br>'; 

exec("/usr/bin/convert -version", $out, $rcode); //Try to get ImageMagick "convert" program version number. 
echo "Version return code is $rcode <br>"; //Print the return code: 0 if OK, nonzero if error. 
echo alist($out); //Print the output of "convert -version" 

echo '<br>'; 
echo '<b>This should test for ImageMagick version 6.x</b><br>'; 
echo '<b>Path: </b> /usr/local/bin/convert<br>'; 

exec("/usr/local/bin/convert -version", $out, $rcode); //Try to get ImageMagick "convert" program version number. 
echo "Version return code is $rcode <br>"; //Print the return code: 0 if OK, nonzero if error. 
echo alist($out); //Print the output of "convert -version"; 

?> 
+1

przekonwertować pdf: Wiele thx. ładny skrypt. działał dobrze zarówno na hostgatorze, jak i na chaddach ... nie tak fajnym jak chmura czy AWS, ale w ramach budżetu moich małych klientów biznesowych. – zipzit

+1

Po godzinach ... tutaj Google to: Błąd MediaWiki: tworzenie miniatur: sh:/usr/local/bin/convert: Brak takiego pliku lub katalogu – Martin

+0

Mine jest aplikacją opartą na .NET i Sitecore. Jak mogę sprawdzić, czy moja aplikacja korzysta z ImageMagick, czy nie? –

30

EDYCJA: Informacje i scenariusz poniżej dotyczą tylko klasy iMagick - która nie jest domyślnie dodawana do ImageMagick !!!

Jeśli chcę wiedzieć, czy jest zainstalowany ImageMagick i rzeczywiście działa jako rozszerzenie php, I wklej ten fragment kodu do strony internetowej dostępnego pliku

<?php 

error_reporting(E_ALL); 
ini_set('display_errors','1'); 

/* Create a new imagick object */ 
$im = new Imagick(); 

/* Create new image. This will be used as fill pattern */ 
$im->newPseudoImage(50, 50, "gradient:red-black"); 

/* Create imagickdraw object */ 
$draw = new ImagickDraw(); 

/* Start a new pattern called "gradient" */ 
$draw->pushPattern('gradient', 0, 0, 50, 50); 

/* Composite the gradient on the pattern */ 
$draw->composite(Imagick::COMPOSITE_OVER, 0, 0, 50, 50, $im); 

/* Close the pattern */ 
$draw->popPattern(); 

/* Use the pattern called "gradient" as the fill */ 
$draw->setFillPatternURL('#gradient'); 

/* Set font size to 52 */ 
$draw->setFontSize(52); 

/* Annotate some text */ 
$draw->annotation(20, 50, "Hello World!"); 

/* Create a new canvas object and a white image */ 
$canvas = new Imagick(); 
$canvas->newImage(350, 70, "white"); 

/* Draw the ImagickDraw on to the canvas */ 
$canvas->drawImage($draw); 

/* 1px black border around the image */ 
$canvas->borderImage('black', 1, 1); 

/* Set the format to PNG */ 
$canvas->setImageFormat('png'); 

/* Output the image */ 
header("Content-Type: image/png"); 
echo $canvas; 
?> 

Powinieneś zobaczyć grafiki Hello World:

enter image description here

5

W bash:

$ convert -version 

lub

$ /usr/local/bin/convert -version 

Nie trzeba pisać żadnych plików PHP tylko do sprawdzenia.

0

Jeśli ISP/usługa hostingu został zainstalowany ImageMagick i umieścić swoje położenie w zmiennej środowiskowej PATH, można znaleźć to, co wersje są instalowane i gdzie przy użyciu:

<?php 
echo "<pre>"; 
system("type -a convert"); 
echo "</pre>"; 
?>