GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   Tech Imagemagick Question (https://gfy.com/showthread.php?t=1352132)

Publisher Bucks 02-10-2022 11:48 AM

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 :)

k0nr4d 02-10-2022 12:29 PM

try

header('Content-Disposition: attachment; filename="whatever.jpg"');

ZTT 02-10-2022 01:17 PM

Doing a church sign generator? I used to love those.

I can't test the code since it uses "imagick", some php extension, but unless there's a reason you have to use that, look into PHP's "imagecreate" function.

And unless you have to use PHP, you can do this kind of stuff with just Javascript and canvas.

Edit: I bothered to RTFM on the "Imagick" github when I was about to close the tab and it's in the Debian repo, so I tried it. Right clicking and saving in Firefox provides the extension, though it's .jpeg, not .jpg, ie "page.php.jpeg".

Publisher Bucks 02-10-2022 02:56 PM

Quote:

Originally Posted by k0nr4d (Post 22963824)
try

header('Content-Disposition: attachment; filename="whatever.jpg"');

Awesome, that worked perfectly, thanks man :)

Any idea about the image overlay / watermark thing? :Oh crap

*edit* How do I stop the whatever.jpg auto downloading on page load?

Publisher Bucks 02-10-2022 03:08 PM

Quote:

Originally Posted by ZTT (Post 22963844)
Doing a church sign generator? I used to love those.

eBook cover generator, hoping itll save my guys some time when it comes to processing new title covers :thumbsup

Just have to figure out why the image overlay stuff isnt working lol

Publisher Bucks 02-10-2022 10:57 PM

One more issue I just discovered...

Quote:

/* Font properties */
$draw4->setFont('Bookman-DemiItalic');
$draw4->setFontSize( 60 );
$draw4->setGravity(Imagick::GRAVITY_CENTER );
Isn't centering the text, any clues as to why?

k0nr4d 02-11-2022 01:05 AM

Quote:

Originally Posted by Publisher Bucks (Post 22963887)
Awesome, that worked perfectly, thanks man :)

Any idea about the image overlay / watermark thing? :Oh crap

*edit* How do I stop the whatever.jpg auto downloading on page load?

I've honestly never used imagemagick from php like that, only from command line.
What about a rewriterule so the image URL ends in .jpg?
line1|line2|line3.jpg or something.


All times are GMT -7. The time now is 10:38 AM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc