Score:0

imagick WriteImage function is not working using Php 7.4

sn flag

I am trying to write images using imagick php extension but code break on write image line. I also comment this line in policy.xml

<!-- <policy domain="coder" rights="none" pattern="PDF" /> -->

I am trying this code

private $path;
private $file;

function __construct($file){
    $this->path = "upload/".$file;
    $this->file = $file;
}
function convertDocument(){

    if ( !is_dir("custom/modules/Contacts/temp") ) {
        mkdir("custom/modules/Contacts/temp",0777,TRUE);       
        chmod("custom/modules/Contacts/temp", 0777);
    }

    $imagick = new imagick();
    $imagick->setResolution(200, 200);
    $imagick->readImage($this->path);
    $imagick->setImageBackgroundColor('white');
    $imagick->setImageAlphaChannel(11);
    $GLOBALS['log']->fatal('Read Image');

    $imagick->setImageResolution(2000, 2000);

    $imagick->setImageFormat('jpg');
    $pages = (int)$imagick->getNumberImages();
    $GLOBALS['log']->fatal('Get Image Pages: '.$pages);

    foreach($imagick as $i=>$imagick) {    
        $GLOBALS['log']->fatal('Write Images '.$i);
        $imagick->writeImage("custom/modules/Contacts/temp/".$this->file."_".$i.".jpg");
    }

    $GLOBALS['log']->fatal('After Writing images, START MERGING');

    $mpdf = new mPDF('en','Letter');

    for($p = 0; $p < $pages; $p++){
        $GLOBALS['log']->fatal('Write Image in PDF '.$p);

        $mpdf->WriteHTML("<img src='custom/modules/Contacts/temp/".$this->file."_".$p.".jpg' />");
    }

    $mpdf->Output('custom/modules/Contacts/temp/'.$this->file.'.pdf');
    $imagick->clear();

    $GLOBALS['log']->fatal('Conversion End .... ');



    return;
}

Please help me how i can solve this issue.

uz flag
Jos
Where do you use the `Imagick` class?
Abdullah Shahab avatar
sn flag
please check now
uz flag
Jos
What is the exact error message that you get?
Abdullah Shahab avatar
sn flag
i using this with job_queue. when code compile this line it give error cron job failed
uz flag
Jos
Is there anyting in `/var/log/syslog` or in `/var/log/apache2/error.log`, in case you run your own webserver? Please provide details.
Abdullah Shahab avatar
sn flag
in error.log getting this [Mon Dec 19 19:46:21.567709 2022] [php7:warn] [pid 22563] [client ::1:33190] PHP Warning: Illegal string offset 'name' in /var/www/html/ftc_live/data/Relationships/One2MRelationship.php on line 107, referer: http://localhost/ftc_live/index.php?module=Contacts&offset=266&stamp=1671453039089100100&return_module=Contacts&action=DetailView&record=e2166290-3594-1390-bc32-6399841f4052
uz flag
Jos
That is a warning, and moreover, there is no 'name' in your program. So this must refer to a different program.
Abdullah Shahab avatar
sn flag
yes its just warnning
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.