Imagemagick Question

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Publisher Bucks
    Confirmed User
    • Oct 2018
    • 1332

    #1

    Tech 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?

    <?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?

    /* 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
    Extreme Link List - v1.0
  • k0nr4d
    Confirmed User
    • Aug 2006
    • 9231

    #2
    try

    header('Content-Disposition: attachment; filename="whatever.jpg"');
    Mechanical Bunny Media
    Mechbunny Tube Script | Mechbunny Webcam Aggregator Script | Custom Web Development

    Comment

    • ZTT
      Confirmed User
      • Apr 2019
      • 659

      #3
      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".
      __________________

      Comment

      • Publisher Bucks
        Confirmed User
        • Oct 2018
        • 1332

        #4
        Originally posted by k0nr4d
        try

        header('Content-Disposition: attachment; filename="whatever.jpg"');
        Awesome, that worked perfectly, thanks man

        Any idea about the image overlay / watermark thing?

        *edit* How do I stop the whatever.jpg auto downloading on page load?
        Extreme Link List - v1.0

        Comment

        • Publisher Bucks
          Confirmed User
          • Oct 2018
          • 1332

          #5
          Originally posted by ZTT
          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

          Just have to figure out why the image overlay stuff isnt working lol
          Extreme Link List - v1.0

          Comment

          • Publisher Bucks
            Confirmed User
            • Oct 2018
            • 1332

            #6
            One more issue I just discovered...

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

            Comment

            • k0nr4d
              Confirmed User
              • Aug 2006
              • 9231

              #7
              Originally posted by Publisher Bucks
              Awesome, that worked perfectly, thanks man

              Any idea about the image overlay / watermark thing?

              *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.
              Mechanical Bunny Media
              Mechbunny Tube Script | Mechbunny Webcam Aggregator Script | Custom Web Development

              Comment

              Working...