Under the hood

August 10, 2009 by nuno costa 4 comments

Learning the internals

For the more curious minds there’s a way to learn ImageMagick commands and to know exactly what phMagick is doing

1
2
3
    $p = new phmagick('results/result.png', 'results/resize.jpg');
    $p->resize(100,75);
    echo '<pre>',print_r ( $p->getLog() ) , '</pre>';

This will output what phMagick is doing as well as any ImageMagick error messages or information

Array
(
    [0] => Array
        (
            [cmd] => convert -scale "100x75>" -quality 80 -strip  "results/result.png" "results/resize.jpg"
            [return] => 0
            [output] => Array
                (
                )
        )
)

4 comments so far Add Your Comment

  1. by Denver Steiner on September 8 2011 at 21:52

    Is there a way to add manual commands? When converting PDFs to JPG, my JPG is coming out looking like crap and is unreadable. In reading a few ImageMagick forums there are some commands I would like to try (like -density 400), but not sure how to use with your class without diving into your original code.

  2. by Denver Steiner on September 8 2011 at 22:14

    I ended up adding my own custom function and variable to the class:
    class phmagick{
    private $custom_cmd = ”;
    ….
    public function setCustomCommand($cd){
    $this->custom_cmd=$cd;
    }

    public function execute($cmd){
    if ($this->custom_cmd) $cmd=”convert “.$this->custom_cmd.” “.str_replace(“convert “,”",$cmd); …

    This seemed to work like a charm. This allowed me to execute this command:
    $p->setCustomCommand(‘-density 400′);
    $p->acquireFrame(‘file.pdf’,0);
    $p->setCustomCommand(”);//reset custom command to blank in case future commands are run.

  3. by Amir Johnson on May 4 2012 at 07:42

    How can we determine, in PHP, whether the conversion/processing was successful? Thank you!

  4. by nuno costa on May 4 2012 at 09:08

    @Amir,

    You can check if the new file is present
    phMagick will throw an exception if something goes wrong

More from francodacosta.com

© francodacosta.com - All rights reserved