• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

XF 2.0 Using imagick

AndrewSimm

Active member
#1
I use imagick to set image sizes in a script I developed for my VBulletin forum. I know I have the imagick installed correctly, but I am having trouble using inside one of the methods inside a controller.

Here is the error I get.

Fatal error: Class 'CIS\News\Pub\Controller\Imagick' not found in
 

Chris D

XenForo developer
Staff member
#2
To call an external class from within a namespace in PHP you need to prefix it with a root slash. e.g. correct:
PHP:
$im = new \Imagick();
incorrect:
PHP:
$im = new Imagick();
As you might guess from the error you're seeing, if you forget the leading slash then it will look for the class within the current namespace.

All that said, bear in mind that XF has a system that supports both GD and Imagick in a totally transparent way, so you may be able to do your manipulations purely using our built in functions.

If you explain in more detail what you normally need to do in Imagick, I'll try and help you convert that to the equivalent code within our image driver.
 

AndrewSimm

Active member
#3
To call an external class from within a namespace in PHP you need to prefix it with a root slash. e.g. correct:
PHP:
$im = new \Imagick();
incorrect:
PHP:
$im = new Imagick();
As you might guess from the error you're seeing, if you forget the leading slash then it will look for the class within the current namespace.

All that said, bear in mind that XF has a system that supports both GD and Imagick in a totally transparent way, so you may be able to do your manipulations purely using our built in functions.

If you explain in more detail what you normally need to do in Imagick, I'll try and help you convert that to the equivalent code within our image driver.
I am creating a mod that will allow a staff member to create news from the post. Once they click the "news" button on the post they are taken to a page where they can enter some details, and select an image to serve as the news image. When the image is uploaded imagick creates 3 different sizes of the image. This allows me to use the correct size, depending on where I render it on the news page. Previously I just used imagick to create thumbnails for player profile images, so I will probably be using some different methods with news. I've added the slash in front of imagick and it works perfectly, so next, I just need to figure out what methods in imagick will work best.