I can't seem to get Imagick::setFont to work in php. Taking the example straight from the man page:
/* Create new imagick object */
$im = new Imagick();
/* Set the font for the object */
$im->setFont("comic.ttf");
/* Create new caption */
$im->newPseudoImage(100, 100, "caption:Hello");
$im->setformat('png');
header('Content-type: image/png');
echo $im;
I get...
http://i53.tinypic.com/2d2bn9x.png
... which is clearly not comic sans. I've tried numerous fonts. It never changes. It does complain if the file doesn't exist. It does not accept names like "Arial".
When you're using setFont method you need to make sure you pass absolute path of the font:
$im->setFont("/var/www/html/mysite/media/fonts/myCustomFont.ttf");
Same would apply for your localhost development just change the absolute path.
(This is a bit old question but I figured to answer it anyways.)
I'm having the same situation here and I found this post
http://www.imagemagick.org/discourse-server/viewtopic.php?f=10&t=11937
They say Freetype library should be installed, but haven't tried yet.
UPDATE
Finally I had chance to try it and It worked.
I use
ImageMagick 6.7.6
Imagick 3.0
Freetype 2.4.9
Freetype-devel 2.3.11
Fontconfig-devel 2.8
PHP 5.3.13
Related
I am using a PHP Thumbnail Generating script that I have used without issue many times in the past. I am currently using it without issue on the very same domain that I am now having problems.
The script is processing to a point. It is generating physical thumbnail images and saving them into the preset cache directory but it is not returning resized images to the browser.
The image src is in the following format:
<img src="thumbnail.php?file=sample/02.jpg&w=100&h=70&el=0&gd=0" />
I have confirmed that the image exists and can be displayed in a browser itself.
Also, the PHP script loads ok as I have tested it by adding an 'echo' to confirm.
I have installed this script in multiple locations on the server and the result is the same. I have even tried other versions of PHP Thumbnail Generators and none of them produce resized images in the browsers.
I have checked that GD is active on my server:
GD Support enabled
GD Version bundled (2.1.0 compatible)
FreeType Support enabled
FreeType Linkage with freetype
FreeType Version 2.4.2
GIF Read Support enabled
GIF Create Support enabled
JPEG Support enabled
libJPEG Version 6b
PNG Support enabled
libPNG Version 1.2.44
WBMP Support enabled
XBM Support enabled
PHP is version 5.3.29
Imagemagick is available and path confirmed as '/usr/bin/convert/'.
Here you see the result:
http://demos.mitey.co.nz/image_processor/index.php
All that appears is broken image placeholders instead of the dynamically generated thumbnails.
All relevant permissions have be set to 0777 or 0755, tried both.
This really isn't a difficult script to use and I have numerous times in the past but I am unable to debug whatever is causing it to fail in this instance.
Anybody have any ideas as to what could be stopping the image source from correctly processing the PHP contained within it?
I have tried so many different things that I can no longer focus on the issue and come up with anything else to try.
SOLVED: I was trying to load images into the script from another sub-domain. The Thumbnail script I was using claims to allow loading images from another domain using http however it thens fails when it comes to the PHP function 'file_exists' which does not work via the http protocol. I removed the 'http://' part of the image path using 'str_replace' and replaced it with the file system path, i.e. /home/siteroot/' and all works as expected. When used with images on the same domain as the thumbnail generating script the script is happy for the full 'http://' path to remain. There was no useful error messages to point this out.
Download the latest PHPthumb from website
For generate thumb see documentation
don't forget to Change variable as per your need.
$thumbUrl = "somefolder/new.jpg";
$resizeWidth = "70"; // in pixels
$resizeHeight = "70"; // in pixels
$imageThumb = $directoryPath. "/phpThumb/phpThumb.php?src=" . $thumb1 . "&w=".$resizeWidth."&h=".$resizeHeight."&iar=1&hash=90e9d46c4d138a72574c52e31fbef0dc";
echo '<img src="'.$imageThumb.'" alt="filename.jpg" />';
This is the first time I use PHP Imagick and experiencing problems with it.
I'm creating a website module where users can upload images that need to be converted to an encrypted file type containing the uploaded image as a DDS texture.
So what I need to do is convert the uploaded image to dds file format.
Code:
$img = new Imagick('test.png'); //Load the uploaded image
$img->setformat('dds'); //Set the format to dds
$img->setImageCompression(Imagick::COMPRESSION_DXT3); //Set compression method
$img->writeimage('test.dds'); //Write/save the dds texture
The problem: the output file is always an empty, 0 byte file.
PNG That needs to be converted: test.png
DDS That needs to be the output: test.dds
Maybe I need other version Imagick or ImageMagick?
My old version of these are:
PHP 5.5.15
Imagick 3.1.2-5.5-ts-vc11-x86
ImageMagick 6.8.4-0-Q16-x86
I am currently testing on Windows 8.1 x64.
Any suggestion/help would be appreciated.
Edit: Edited the question, hopefully its clear now what I am trying to achieve.
Solved: The problem was the version of ImageMagick that had no support for DDS write.
Installed ImageMagick 6.8.6-10-Q16-x86 since the DDS write support was added in that version (newer versions caused the imagick not to be loaded).
Current version of what I use and works:
PHP 5.5.15
Imagick 3.1.2-5.5-ts-vc11-x86
ImageMagick 6.8.6-10-Q16-x86
From the debugging above the issue is that your version of ImageMagick doesn't support writing DXT3 compressed DDS files.
The options to solve this problem are:
Use a different compression format - DXT5 might be okay, but it's not exactly the same as DXT3.
Upgrade to a newer version of ImageMagick and Imagick that support writing in DXT3 format.
I'm looking to use image masks in Typo3. After trying out various things and none of them worked, I decided to check out the install tool.
Install tool says ImageMagick is installed correctly, paths are correct and all image test complete successfully, except the convert/combine test. The test says "There was no result from the ImageMagick operation".
Also, when I'm using gifbuilder to output an image the image's dimensions get read correctly, allthough the outputted image stays blank. (which is white or another color when I have backColor set)
I am using:
Max OSX 10.7.5
XAMPP
PHP 5.3.1
Typo3 6.0.4
ImageMagic 6.7.3-2
Here is some test typoscript code (which on my install results in a fully red image instead of the original image)
lib.test = IMAGE
lib.test {
file = GIFBUILDER
file {
XY = [10.w],[10.h]
backColor = #FF0000
10 = IMAGE
10.file = fileadmin/user_upload/test.jpg
}
}
Attached is the result from the combining images test.
Does anyone have an idea as to what I might be doing wrong?
Some newer imagemagick versions use composite as command instead of combine. There is an option in the install tool to set the command to use. The setting is called [GFX][im_combine_filename].
I am working on creating thumbnail image from the first page of pdf file. I almost tired every solution available on the web to make ImageMagick running but I still get the following error
Fatal error: Class 'Imagick' not found in C:\wamp\www\mediabox\application\controllers\cron.php on line 153
what I have done so far.
Installed GPL Ghostscript
Installed ImageMagick-6.7.6-Q16
Downloaded and copied the php_imagick.dll file in ext folder of my php installation.
Added extension=php_imagick.dll line to my php.ini file.
Restarted the apache server and windows many times :)
I am using codeigniter framework.
Php 5.3.10, apache 2.2.21, mysql 5.5.20, wamp 2.2 and win 7
On my localhost page in the loaded extensions category 'Imagemagick is not listed'
The code I have written is as
$image = explode('.', $filename_new);
$image_name = 'files/import/' . $ftp_upload["path"] ."/". $image[0] .".jpg";
//exec("convert -colorspace RGB -geometry 300x400! -density 200 " .$pdf_file."[0] ". $image_name);
$img = $image[0].".jpg" ;
$im = new Imagick($img);
$im->pingImage($img);
$im->readImage($img);
$im->thumbnailImage(100, null);
$im->writeImage( 'files/import/' . $ftp_upload["path"] ."/".$img);
$im->destroy();
The exec command create images but it is very slow I want to create thumbnail images using Imagick class and I hope it will be faster as compared to exec and convert thingy.
Any ideas what should I do to make the Imagick class available for my php ?
Thanks
I am not sure where you got your binaries from, but it seemed like something I experienced about a month ago. Some of the binaries I tried would show up in phpinfo(), but refused to work, whereas others wouldn't even show in phpinfo().
I then just went ahead and compiled my own binaries as per my question here.
I just went and compiled those binaries for you. They are for x86, compiled with VC9 and there are threadsafe and non-threadsafe versions. The version is 3.1.0RC1 (latest).
You can download them here: http://min.us/mtg0Z66BI
Let me know if it works for you :)
On my server the pecl-imagick extension only works with mod_mpm_prefork - it does not work with mod_mpm_worker.so or mod_mpm_event.so
That may be your issue.
If you are only creating jpg add the jpg hint to the exec( ) command which will be faster than Imagick.
Use -define jpeg:size=200x200 before reading the image in - 200x200 is the output image size.
I suspect Imagick is not installed correctly
I am using ImageMagick with the PHP IMagick API to process uploaded jpg files - however, when I try to read a Blob or even read a physical file, I get a NoDecodeDelegateForThisImageFormat exception.
An example of the code I am using is below:
private function resizeImageBlob($blob, $width, $height) {
$image = new Imagick();
$image->readImageBlob($blob);
$image->resizeImage($width, $height, IMAGICK::FILTER_LANCZOS, 1);
$resizedBlob = $image->getImageBlob();
return $resizedBlob;
}
The image that the blob represents is a jpg image, but ImageMagick throws the exception when it tries to read the line:
$image->readImageBlob($blob);
Does anybody know why this might be happening?
I figured out the answer to my problem. The reason the exception was occurring was indeed due to the fact that the library did not have jpeg support built in, but the reason this happened was because the Imagick php extension's version and the ImageMagick library's version were different.
A good way to make sure not to run into this problem is to download both the ImageMagick library and the Imagick php extension, and specifically look at the versions to see that they match.
Alternatively, you can check the version of your Imagick php extension in the php/ext folder by enabling it in your php.ini file, and using
echo phpinfo();
to check the version of the extension. Then, you can download the same version of the ImageMagick library.