Page 1 of 2
Install and use ImageMagick with PHP
Posted: 2010-11-02T13:40:55-07:00
by YBthebest
Hello! The title says it all...I found a tutorial that uses ImageMagick, and I would want to use it! I searched about it, but I just can't find the solution...
1.
exec("/usr/local/bin/convert /home/cra/cap.jpg -quality 100 /home/cra/cap.jpg");
2.
//optimize
3.
exec("/usr/local/bin/convert /home/cra/cap.jpg -fuzz 25000 -fill black -draw ‘color 5,5 floodfill’ -quality 100 /home/cra/cap_c.jpg");
4.
//floodfill and fill bg in black
5.
exec("/usr/local/bin/convert /home/cra/cap_c.jpg -negate -quality 100 /home/cra/cap_h.jpg");
6.
//negate the picture
7.
8.
exec("/usr/local/bin/convert /home/cra/cap_h.jpg -shave 10×10 -quality 100 /home/cra/cap_cra.jpg");
9.
//remove the border
This is the code...how can I use it?
Thank you very much for the help
Re: Install and use ImageMagick with PHP
Posted: 2010-11-02T13:50:46-07:00
by Bonzo
Is imagemagick installed:
Code: Select all
<?php
echo "<pre>";
system("convert -version");
echo "</pre>";
?>
What is the path to imagemagick:
Code: Select all
<?php
echo "<pre>";
system("type convert");
echo "</pre>";
?>
OR
<?php
echo "<pre>";
system('which convert',$path); print_r($path);
echo "</pre>";
?>
If the above is OK just run your code
Re: Install and use ImageMagick with PHP
Posted: 2010-11-02T14:00:57-07:00
by YBthebest
Version: ImageMagick 6.6.0-4 2010-08-11 Q16
http://www.imagemagick.org
Copyright: Copyright (C) 1999-2010 ImageMagick Studio LLC
Features: OpenMP
Seams it's installed
/usr/bin/convert
and that's the path...so yeah, seems all right
Thanks man
really, thanks
Re: Install and use ImageMagick with PHP
Posted: 2010-11-02T14:09:04-07:00
by Bonzo
Thats Ok; you may be able to just use convert rather than usr/bin/convert I also use relative paths.
Do not forget to CHMOD the folder you are saving the images into to 755 or 777
Do not save intermediate images as jpg as they get compressed and the code you posted can be improved - if you have problems check my examples or post info on what you are trying to do.
Re: Install and use ImageMagick with PHP
Posted: 2010-11-02T14:17:35-07:00
by YBthebest
Hey, you just posted after my 2nd post so I assume you didn't see it...as I said, I'm a bit lost with the folders!
And I don't understand, why can't I save it as .jpg?
Thanks!
Re: Install and use ImageMagick with PHP
Posted: 2010-11-02T14:20:51-07:00
by Bonzo
jpg is a lossy compression - everytime you save an intermediate image; one you are going to edit again as in your example code - you lose some detail. In that case save the imtermediate images as something like a png which is not compressed.
If you use relative paths they are in relation to where your code is.
Re: Install and use ImageMagick with PHP
Posted: 2010-11-02T14:28:57-07:00
by YBthebest
Ok I understand!
But I still don't get the folder thing, wth is the usr bin convert thing? I can't find it! and the output folder I can just put: image/image.png?
Thanks!
Re: Install and use ImageMagick with PHP
Posted: 2010-11-02T14:33:46-07:00
by Bonzo
Do not worry about the usr/bin/convert that is the path to Imagemagick.
Start simple just put your code in a folder along with your image ( e.g. called input.jpg ) and save to the same folder - CHMOD the folder to 755 or 777.
Code: Select all
<?php
exec("/usr/bin/convert input.jpg -bordercolor black -border 10x10 output.jpg");
?>
<img src="output.jpg">
Re: Install and use ImageMagick with PHP
Posted: 2010-11-03T05:28:56-07:00
by YBthebest
Wooooow! I love ya man ! Thank you sooo much!
EDIT: There is just one thing! It gives me a black background and white letters and shapes, while it should be white background and black letters and shapes!
Is that normal? Thanks!
Re: Install and use ImageMagick with PHP
Posted: 2010-11-03T13:19:51-07:00
by YBthebest
I don't really understand, I'm trying too but...it's difficult
Re: Install and use ImageMagick with PHP
Posted: 2010-11-03T13:36:12-07:00
by Bonzo
The code you posted is a bit of a mess do you have an example or description of what you are trying to do?
Re: Install and use ImageMagick with PHP
Posted: 2010-12-01T09:51:30-07:00
by YBthebest
Hello!
So I managed to make the code work !
<?php
exec("/usr/bin/convert image.jpg -quality 100 image.jpg");
//optimize
exec("/usr/bin/convert image.jpg -fuzz 25000 -fill black -draw ‘color 5,5 floodfill’ -quality 100 image_c.jpg");
//floodfill and fill bg in black
exec("/usr/bin/convert image_c.jpg -negate -quality 100 image_h.jpg");
//negate the picture
exec("/usr/bin/convert image_h.jpg -shave 11×14 -quality 100 image_cracked.jpg");
?>
So, this is my basis image:
http://ybthebest.com/test/image.jpg
And this is my final image:
http://ybthebest.com/test/image_final.jpg
But as you see, there is still that annoying background with the white lines on it...how can I get rid of that and ONLY have the 2 numbers and the sign?
Thanks !
Re: Install and use ImageMagick with PHP
Posted: 2010-12-01T11:03:00-07:00
by Bonzo
Is this a CAPTCHA on someone elses website you are trying to crack ?
Re: Install and use ImageMagick with PHP
Posted: 2010-12-01T11:24:45-07:00
by YBthebest
Hello!
Thanks for your answer!
Nope, I'm not trying to crack someone elses captcha. Some people asked me to input a captcha on their website, and I wanted to make it myself (I can give you the code if you want !)
And I want to test if it is crackable, and how it works. ImageMagick and gOCR interest me very much, so...
Thanks!
Re: Install and use ImageMagick with PHP
Posted: 2010-12-01T11:28:31-07:00
by Bonzo
OK try these two - one will give you white text on a black background and the other black text on a white background:
Code: Select all
exec("/usr/bin/convert image.jpg -negate -black-threshold 30% -trim 3image_c.jpg");
exec("/usr/bin/convert image.jpg -white-threshold 70% -trim 4image_c.jpg");