i installed imagick library and download dll file from
http://valokuva.org/outside-blog-content/imagick-windows-builds/php53/imagick-2.3.0-dev/vc9_zts/php_imagick.dll
and copy to wamp/bin/php/php5.3/ext/php_imagick.dll and i see this message from wamp after add this line to php.ini :
extension=php_imagick.dll
wamp messege:
module 'imagick' already loaded
and in phpinfo() there are imagick table.
but when i run this php code that come in below:
$image = new Imagick("./s/Page_ (1).jpg");
$image->cropImage(2242,3090, 120,210);
$flag = $image->writeImage("./c/Page_ (1).jpg");
if($flag){
echo "true ";
}else{
echo "false ";
}
but i have not any response and after some loading i see this error from windows:
Apache HTTP Server has encountered a problem and needs to close. We
are sorry for the inconvenience.
and in "./c/Page_ (1).jpg" is not any cropped picture!
notice: "./s/Page_ (1).jpg" is a jpeg file in size: 2482x3510
please help me :(
Related
I have a problem moving my script from one server to one other.
The PHP script read a PDF file and create an image for each page of the pdf.
This script currently works in an environment that has these characteristics
PHP version: 7.4.8
Imagick version: 3.4.4
Now I have moved the script to an environment that has these characteristics:
PHP version: 7.4.28
Imagick version: 3.7.0
The code is:
$img = new Imagick($percorsoBaseDir); //LINE OF THE ERROR
$img->setResolution(600, 600);
$num_pages = $img->getNumberImages();
$img->setImageCompressionQuality(100);
$images = NULL;
for ($i; $i < $num_pages; $i++)
{
..... [My script] ....
}
And the error is:
AH01071: Got error 'PHP message: PHP Fatal error: Uncaught ImagickException: Failed to read the file in /var/www/vhosts/mysite.com/httpdocs/wp-content/plugins/custom_plugin/includes/woocommerce/Step_2.php:222\nStack trace:\n#0 /var/www/vhosts/mysite.com/httpdocs/wp-content/plugins/custom_plugin/includes/woocommerce/Step_2.php(222): Imagick->readImage()\n#1 /var/www/vhosts/mysite.com/httpdocs/wp-includes/shortcodes.php(356): step_2_function()\n#2 [internal function]: do_shortcode_tag()\n#3 /var/www/vhosts/mysite.com/httpdocs/wp-includes/shortcodes.php(228): preg_replace_callback()\n#4 /var/www/vhosts/mysite.com/httpdocs/wp-content/plugins/js_composer/include/helpers/helpers.php(247): do_shortcode()\n#5 /var/www/vhosts/mysite.com/httpdocs/wp-content/plugins/js_composer/include/templates/shortcodes/vc_column_text.php(31): wpb_js_remove_wpautop()\n#6 /var/www/vhosts/mysite.com/httpdocs/wp-content/plugins/js_composer/include/classes/shortcodes/core/class-wpbakeryshortcode.php(451): require('/var/www/...',
I also tried throwing:
getcwd() //to verify that the file exists
and:
is_readable ($ pathBaseDir) //to verify that the file exist and is readable
is_writable ($ pathBaseDir) //to verify that the file exist and is writable
and they both return TRUE.
I also checked that the file loaded correctly in the file system and that I could open it from the browser.
I can't understand what can be the error, has something similar happened to you? How could I solve?
Thank you!
I find the problem: I have installed the Ghost Script in my server with this command:
apt-get install ghostscript
And now it works!
I have trouble using simpliest PHP (php version 7.4, XAMPP environment) code for image resize, with ImageMagick. It causes Apache server error The connection was reset (ERR_CONNECTION_RESET).
Here is code:
<?php
function resizeImage($imagePath) {
$imagick = new \Imagick(realpath($imagePath));
$imagick->resizeImage(320,240, \Imagick::FILTER_LANCZOS,1); // trouble line
header("Content-Type: image/jpg");
echo $imagick->getImageBlob();
//$imagick->writeImage("./output.png");
exit;
}
$imagePath = '/xampp/htdocs/devel/images/tumb500.jpg';
resizeImage($imagePath);
?>
Update:
Error in Apache logs related to this is:
PHP Warning: Version warning: Imagick was compiled against ImageMagick version 1799 but version 1803 is loaded. Imagick will run but may behave surprisingly in Unknown on line 0
But - checked and I have same error on other server where this code work properly.
And also, I tried with different (older) versions of ImageMagick and I have same error all the time.
Also to mention that other Imagick methods work properly.
Can you help me what I'm doing wrong here?
when using imagick to count the page number of pdf file it shows the error. PDFDelegateFailed `The system cannot find the file specified.' # error/pdf.c/ReadPDFImage/801 error is showing.Iam using Xampp server and i installed ghost script to resolve this error my apache stops working.
$image = new Imagick();
$image->pingImage($path);
echo $image->getNumberImages();
When i try using the GD Library in PHP 7.4.6 on my Windows PC, it shows me this error:
Fatal error: Uncaught Error: Call to undefined function imagecreate() in C:\Users\user\Desktop\Site\index.php:11 Stack trace: #0 {main} thrown in C:\Users\user\Desktop\Site\index.php on line 11
The line 11 is:
$image = imagecreate(200,20);
The full PHP code is:
<?php
$image = imagecreate(200,20);
$background = imagecolorallocate($image,0,0,0);
$foreground = imagecolorallocate($image, 255,255,255);
$imagestring($image,5,5,1,"Test",$foreground);
$header("Content-type: image/jpeg");
$imagejpeg($image);
?>
I tried fixing this by following this guide, and i uncommented the GD line, but it still gives me this error.
Thanks in advance.
Do a php -m to see PHP modules. If you can't find gd there then you need to install and enable that extension. There a lot of tutorials in internet to doing so
I had the same problem with apache and GD.
See https://stackoverflow.com/a/72565820/9630486
The problem was in php.ini path for apache. By default it is not using php.ini from php directory. You need to define PHPIniDir in httpd file or place copy of php.ini to apache folder.
Go to php.ini file search this
;extension=gd
Remove ; then restart the server
Try this code:
<?php
phpinfo();
Search for "GD Support" in the resulting output. If you don't see it or it's not enabled, you need to enable gd in php.ini - search for:
;extension=php_gd2.dll
Remove the comment in front of it, save the ini file, and restart IIS/Apache/Nginx/whatever server you're running.
So I'm currently using "Imagick" extension for a symfony project, but I get this error:
ClassNotFoundException: "Attempted to load class "Imagick" from the global namespace. Did you forget a "use" statement?"
Strangely, it's working fine in all native php script, but not working in symfony project!
I did some research and I found that I need to enable imagick for CLI also .. but I didn't find any method explain how to make it.
So, I verified Imagick installation by this code snippet:
<?php
header('Content-type: image/jpeg');
$image = new imagick("C:/wamp64/www/test/image.jpg");
$image->thumbnailImage(100,0);
echo $image;
and I can see the image loaded correctly.
Also, when I run this script from the browser:
<?php
if (extension_loaded('imagick')){
echo 'imagick is installed';
} else {
echo 'imagick not installed';
}
?>
I get :
imagick is installed
But when I execute this file from command-line interface, I get :
imagick not installed
In the Symfony project I get this error log:
Uncaught PHP Exception Symfony\Component\Debug\Exception\ClassNotFoundException: "Attempted to load class "Imagick" from the global namespace. Did you forget a "use" statement?"
Symfony function
private function createThumbnail($path, $dest, $width, $height)
{
$im = new \Imagick();
$im->pingImage($path);
$im->readImage($path);
$im->thumbnailImage($width, $height);
$white=new \Imagick();
$white->newImage($width, $height, "white");
$white->compositeImage($im, \Imagick::COMPOSITE_OVER, 0, 0);
$white->setImageFormat('jpg');
$white->writeImage($dest);
$im->destroy();
$white->destroy();
}
Environment
PHP Version => 7.1.9
System => Windows 10
Server => Wamp64
Symfony version => 3.1
Compiler => MSVC14 (Visual C++ 2015)
Architecture => x64
imagick module version => 3.4.3
ImageMagick version => ImageMagick 6.9.3-7 Q16 x64 2016-03-27
The complete ImageMagick/Symfony installation steps are the following (here for Windows):
Download the package from https://pecl.php.net/package/imagick/3.5.1/windows
Extract from php_imagick-….zip the php_imagick.dll file, and save it to the ext directory of your PHP installation
Extract the dependencies
• For PHP 5.x/7.x: Extract from ImageMagick-….zip the DLL files located in the bin folder that start with CORE_RL or IM_MOD_RL or FILTER, and save them to the PHP root directory (where you have php.exe), or to a directory in your PATH variable:
• 17 files CORE_RL*.dll
• 126 files IM_MOD_RL*.dll
• 1 files FILTER*.dll
• For PHP 8.x: Extract from php_imagick-….zip the DLL files that start with CORE_RL or IM_MOD_RL or FILTER, and save them to the PHP root directory (where you have php.exe), or to a directory in your PATH variable
Add this line to your php.ini file: extension=php_imagick.dll
Restart the Apache/NGINX Windows service (if applicable)
Check if the install is correct through phpinfo() for which a specific imagick block has been added
Don’t forget to add use Imagick; to your php file
I found the solution, I put the answer for someone who have the same issue:
you should add the following lines
;on Windows:
extension=php_imagick.dll
;on UNIX:
extension = imagick.so
to C:\wamp64\bin\php\phpx.x.x\php.ini
not to C:\wamp64\bin\apache\apachex.x.x\bin\php.ini
because the first php.ini is the file used by PHP CLI, so by the Symfony Local Web Server.
Happy coding!