I have an EPS file from Photoshop with a clipping path on it:
EPS File
I need to get a thumbnail from this file, so I have the following code:
$img = new imagick();
$img->readimage($uploadfile);
$img->trimimage();
$img->setImageFormat("jpeg");
$img->scaleImage(200,200);
$img->writeimage($uploaddir . $thumb . ".jpg");
I get the following:
Thumb bad
Instead of what I need:
Thumb ok
If I open the file on Photoshop and remove the path by hand I can see it ok, but I have around 3000 images like this, so I need to do this automatically.
Related
I am converting PDF files to PNG files using imagick in PHP.
For this example I have a PDF file with only 5 lines of text on the first (and only) page. This PDF is generated from a Word file (it's not scanned in).
My code to convert the file looks like this:
$im = new Imagick();
$im->setResolution(200,200);
$im->readImage($_SERVER['DOCUMENT_ROOT'] . '/codeigniter/vrm/documents/uploaded_documents/2020/04/buddy_voor_lennert-01042020130414.pdf[0]');
$im->scaleImage(500,500);
$im->setImageFormat('png');
$im->writeImage($_SERVER['DOCUMENT_ROOT'] . '/codeigniter/vrm/documents/images/thumbnails/lennert.png');
$im->clear();
$im->destroy();
After this, the png is created, but the quality of the text is horrible, it becomes unreadable, see the screenshot i attached below.
How do I retain the same quality? I want to generate a thumbnail and a normal size image. So the thumbnail can be of lower quality, but the normal size image should be at least of a readable quality.
I've tried putting the resolution down to 50x50 or tried using the following methods, to no avail:
$im->setImageCompressionQuality(0); (also to 100)
$im->resizeImage(500, 500, Imagick::FILTER_LANCZOS, 0, true);
I have to convert a gif image to png image. For which i have tried this. The image file is in folder ( localhost ).
I have tried the below code.
$imageFile = "14981180607.gif";
$temp = sys_get_temp_dir();
file_put_contents($temp, file_get_contents($imageFile) );
exec("convert ".escapeshellarg($temp)." img/xx_%05d.png");
I need the image to be converted and store in my img folder, which i mentioned the path.
I found more topics from this web site about quality with Imagick but nothing help me...
I have to save all images as JPG. I created this script:
$image_url = 'http://limuzynamercedes.pl/wp-content/uploads/2014/06/3.png';
$image_code = file_get_contents($image_url);
$img = new Imagick();
$img -> readImageBlob($image_code);
$img->setResolution(300, 300);
$d = $img->getImageGeometry();
$img->cropImage($d['width'],($d['height']-120), 0,0);
$img->setImageFormat('jpeg');
$img->setImageCompression(imagick::COMPRESSION_JPEG);
$img->setCompressionQuality(100);
$img->writeImage('read.jpg');
$img->clear();
echo '<img src="read.jpg?'.time().'">';exit;
Here is original image: http://limuzynamercedes.pl/wp-content/uploads/2014/06/3.png
and here is image which was converted by my script: http://s5.ifotos.pl/img/demo1jpg_saeaxqx.jpg
Where is a problem? Why this image is always convert in bad quality?
Thanks.
The image is not in "bad quality" (there is no blurry areas found), but the difference between 2 images is caused by transparent PNG to JPG conversion.
Before you crop the image, add these two lines:
// set background to white (Imagick doesn't know how to deal with transparent background if you don't instruct it)
$img->setImageBackgroundColor(new ImagickPixel('white'));
// flattens multiple layers
$img = $img->mergeImageLayers(Imagick::LAYERMETHOD_FLATTEN);
When I use Imagick in PHP to resize PNG images, the output images are black. This is not the case when I resize JPGs; the PHP procedure (provided below) works perfectly for JPGs, so I suspect there's a missing step when processing PNG files.
I've first tested the conversion using ImageMagick on my local computer using this command:
convert x.png -resize 528 -filter Lanczos x-resized.png
...and it works; the resulting PNG file displays and is resized appropriately.
However, when I attempt to do the same on my server (both localhost and live), the result is a black image.
The PHP code I'm using is:
$source = "x.png" // I provide the complete path in my routine, etc.
$destination = "x-resized.png" // likewise.
$im = new Imagick();
$im->readImage($source);
$im->setImageFormat("png");
$im->resizeImage(528, null, Imagick::FILTER_LANCZOS, 1);
$im->writeImage($destination);
$im->clear();
What am I doing incorrectly?
I'm trying to append several images together into one big image, but the first hurdle is actually just getting the image to open.
I am attempting to do the following:
Open image from path
Size it with the specified dimensions
Save it to the current folder
I have the following:
define('WIDTH', 600);
define('HEIGHT', 800);
$img = new Imagick();
$img->readImage('dress.jpg');
$img->writeImage('image1.png');
I can get the image to save, but I do not know where to add the WIDTH and HEIGHT definitions?
I tried doing the following:
$img->newImage(WIDTH, HEIGHT, $img);
$img = new Imagick();
$img->readImage('dress.jpg');
$img->resizeImage(WIDTH, HEIGHT, Imagick::FILTER_LANCZOS, 1);
$img->writeImage('image1.png');
After "creating" an image resource with new Imagick() you are "working" in that resource. readImage() reads the image which is then present in the resource - after that you can resize the resource and write it out after the work is done.
See the documentation for more info Imagick::resizeImage()
With new Imagick(WIDTH, HEIGHT) you create an image resource with an empty canvas of the given size.