Thread: Tech Imagemagick Question
View Single Post
Old 02-10-2022, 11:48 AM  
Publisher Bucks
Confirmed User
 
Industry Role:
Join Date: Oct 2018
Location: New Orleans, Louisiana. / Newcastle, England.
Posts: 1,116
Imagemagick Question

This code is working fine, however, when I right click on the image to save it, it doesnt have a .jpg extension, any idea why?

I have the header and extension in the code which should be enough to render it as a .jpg shouldnt it?

Quote:
<?php
/* Create some objects */
$image = new Imagick();
$draw = new ImagickDraw();
$draw1 = new ImagickDraw();
$draw2 = new ImagickDraw();
$draw3 = new ImagickDraw();
$draw4 = new ImagickDraw();
$pixel = new ImagickPixel( '#0076a3' );

/* New image */
$image->newImage(2000, 3000, $pixel);

$rect = [
'x' => 175,
'y' => 1850,
'h' => 1000,
'w' => 1650,
];

// Draw a Region-of-interest for reference.
$roi = new ImagickDraw();
$roi->setFillColor('#292b2a');
$roi->rectangle($rect['x'],
$rect['y'],
$rect['x'] + $rect['w'],
$rect['y'] + $rect['h']);
$image->drawImage($roi);

$rect = [
'x' => 0,
'y' => 0,
'h' => 75,
'w' => 2000,
];

// Draw a Region-of-interest for reference.
$roi = new ImagickDraw();
$roi->setFillColor('#292b2a');
$roi->rectangle($rect['x'],
$rect['y'],
$rect['x'] + $rect['w'],
$rect['y'] + $rect['h']);
$image->drawImage($roi);

/* Text Color */
$draw->setFillColor('#FFFFFF');

/* Font properties */
$draw->setFont('Bookman-DemiItalic');
$draw->setFontSize( 110 );

/* Text Color */
$draw1->setFillColor('#0076a3');

/* Font properties */
$draw1->setFont('Bookman-DemiItalic');
$draw1->setFontSize( 200 );

/* Text Color */
$draw2->setFillColor('#FFFFFF');

/* Font properties */
$draw2->setFont('Bookman-DemiItalic');
$draw2->setFontSize( 75 );

/* Text Color */
$draw3->setFillColor('#FFFFFF');

/* Font properties */
$draw3->setFont('Bookman-DemiItalic');
$draw3->setFontSize( 75 );

/* Text Color */
$draw4->setFillColor('#0076a3');

/* Font properties */
$draw4->setFont('Bookman-DemiItalic');
$draw4->setFontSize( 60 );

/* Create text */
$image->annotateImage($draw, 220, 2050, 0,
'Text');

/* Create text */
$image->annotateImage($draw1, 370, 2250, 0,
'Text');

/* Create text */
$image->annotateImage($draw2, 225, 2375, 0,
'Text');

/* Create text */
$image->annotateImage($draw3, 600, 2475, 0,
'Text');

/* Create text */
$image->annotateImage($draw4, 575, 2750, 0,
'Text');

/* Give image a format */
$image->setImageFormat('jpg');

/* Output the image with headers */
header('Content-type: image/jpg');
echo $image;?>
Also, im trying to overlay an image on top of the main body, I have tried the code below but it does not seem to be working, is there a better way of achieving it?

Quote:
/* Overlay image */
$image->readImage('watermark.png'), 2000, 1500, 0,
$image->setImageAlpha(0.5);
$image->compositeImage($wm, Imagick::COMPOSITE_OVER, 0, 0);
$image->writeImage('final.jpg');
Thanks for any assistance or pointers you can give
__________________
NOTHING TO SEE HERE
Publisher Bucks is online now   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote