0

I want to learn how to use the php function imagefilter

I follow a tutorial on youtube and I get this code :

<?php 
$image = imagecreatefromjpeg('../img/Flo.jpg')
$amountOfBlur = 10;

for($i=0;$i<=$amountOfBlur;$i++){
    imagefilter($image, IMG_FILTER_GAUSSIAN_BLUR);
}


imagejpeg($image);
imagedestroy($image);
?>

but the result is wrong, the image is not loading. what should i do?

see the result :

photo display wrong

Thank you for your help, i just need a start.

Souss
  • 1
  • 3
  • try this: https://stackoverflow.com/questions/42759135/php-best-way-to-blur-images – obl Oct 22 '17 at 18:53
  • or try this: https://stackoverflow.com/questions/20261869/php-implementation-of-stackblur-algorithm-available/20264482#20264482 – Sysix Oct 22 '17 at 18:56

3 Answers3

0

you can use this code here. I´ve tested it:

    <?php
    // the name of your first image
    $image = imagecreatefromjpeg('Flo.jpeg');
    imagefilter($image, IMG_FILTER_GAUSSIAN_BLUR);
    // the name of the output image
    imagejpeg($image, 'name_of_the_new_image.jpeg');
    imagedestroy($image);
    ?>

Please note that a new image will be created in the same directory. But if you want to display the new image on your website, just link the image ( here: name_of_the_new_image.jpeg ) inside an <img> tag in your PHP Document.

Source: https://www.phpied.com/image-fun-with-php-part-2/

0

You're not setting the correct content-type. If you're going to output raw JPEG data, you have to explicitly tell the browser that you're giving it a JPEG image and not HTML.

Add header('Content-Type: image/jpeg'); before callingimagejpeg` and you should be all set.

MatsLindh
  • 49,529
  • 4
  • 53
  • 84
0

Great it's working. It's good to know it creates a new file, i didn't notice that. Using the loop "for", the code turn to :

    <?php
$image = imagecreatefromjpeg('Flo.jpeg');

$amountOfBlur = 50;

for($i=0;$i<=$amountOfBlur;$i++){
    imagefilter($image, IMG_FILTER_GAUSSIAN_BLUR);
}

// the name of the output image
imagejpeg($image, 'flo2.jpeg');
imagedestroy($image);
?>

I can now start work on it, improving this code and mix different Image_filter functions to obtain nice results.

PS : i tried :

header('Content-Type: image/jpeg');

My screen turned black....

Souss
  • 1
  • 3