i have a problem with ImageMagick (PHP version), when i make perspective distortion for a photo, for some new posints (sharp shapes) it draws gray shadows on the result image, i think it's like 3D Shadows of the object, but i can not prevent it from coming in !
here is my code:
$controlPoints= array(
$oldPoints[0] , $oldPoints[1] , $newPoints[0] , $newPoints[1],
$oldPoints[2] , $oldPoints[3] , $newPoints[2] , $newPoints[3],
$oldPoints[4] , $oldPoints[5] , $newPoints[4] , $newPoints[5],
$oldPoints[6] , $oldPoints[7] , $newPoints[6] , $newPoints[7]);
$imagick = new imagick();
$imagick->readimageblob($data);
$imagick->setImageMatte(true);
$imagick->setImageVirtualPixelMethod(\Imagick::VIRTUALPIXELMETHOD_TRANSPARENT);
$imagick->distortImage( Imagick::DISTORTION_PERSPECTIVE, $controlPoints, TRUE );
could you please help me, is there any suggestions ?
I tried to remove this gray color from the image result, but it's not good solution if the original photo has the same color in it.
Regards
Hani
Related
I try to use the Gifcreator php class to create an animated GIF image from 10 PNG images.
The animated image is created but transparency of original images is lost. I have a black bakground.
The documentation says that the transparency is determinated by first loaded image. The 10 images have a transparent background. I loaded htem in Paint whicj says that it is based on white.
Has anoyone a solution to this ?
Thanks,
The class is here : https://github.com/Sybio/GifCreator
My script here : http://www.egloff.eu/rsmaptest/slideshow.php
The first image here : http://www.egloff.eu/rsmaptest/images/image0.png
The code :
<?php
// Include the class
require_once('./testcreator/GifCreator.php');
// Instanciate the class (uses default options with the addition of width/height specified)
$gif = new GifCreator(0, 2, array(0, 0, 0),550,550);
// Add each frame to the animation
$gif->addFrame(file_get_contents('images/image9.png'), 100, true);
$gif->addFrame(file_get_contents('images/image8.png'), 100, true);
$gif->addFrame(file_get_contents('images/image7.png'), 100, true);
$gif->addFrame(file_get_contents('images/image6.png'), 100, true);
$gif->addFrame(file_get_contents('images/image5.png'), 100, true);
$gif->addFrame(file_get_contents('images/image4.png'), 100, true);
$gif->addFrame(file_get_contents('images/image3.png'), 100, true);
$gif->addFrame(file_get_contents('images/image2.png'), 100, true);
$gif->addFrame(file_get_contents('images/image1.png'), 100, true);
$gif->addFrame(file_get_contents('images/image0.png'), 500, true);
// Output the animated gif
header('Content-type: image/gif');
echo $gif->getAnimation();
?>
I found an answer to my own question, and it might help some others using the same library or other libraries based on the same original work by László Zsidi.
In the class, you have to replace the following part that appears in one or another place in 2 lines :
$Locals_ext = "!\xF9\x04" . chr ( ( $this->DIS << 2 ) + 0 ) .
by this one
$Locals_ext = "!\xF9\x04" . chr ((( $this->DIS << 2 )) | 1 + 0 ) .
That solved my problem and transparency works now OK. i tried in 3 differents classes i've found are all based on the same work.
I hope this can help.
I want to know if there is a way to create a ppt file with pre defined width and height rather than default one.
I've used this code to set it for the new PHPPresentation (newer PHPPowerpoint version).
Hope it helps..(replace path's with your phppresentation path's
and width(1180) and height(768) to suit yours
/*Standard library loaders */
require_once 'include/Common/src/Common/Autoloader.php';
\PhpOffice\Common\Autoloader::register();
require_once 'include/PHPPowerPoint2/src/PhpPresentation/Autoloader.php';
\PhpOffice\PhpPresentation\Autoloader::register();
/*Standard library loaders */
use PhpOffice\PhpPresentation\PhpPresentation;
use PhpOffice\PhpPresentation\DocumentLayout;
$objPHPPowerPoint = new PhpPresentation();
$objPHPPowerPoint->getLayout()->setDocumentLayout(DocumentLayout::LAYOUT_CUSTOM, true)
->setCX( 1180, DocumentLayout::UNIT_PIXEL)
->setCY( 768, DocumentLayout::UNIT_PIXEL);
The answer of #user2633993 is still valid, though the code for setting the layout width and height has changed a bit, now you need to set an array containing the cx and cy keys, their values doesn't matter.
So the code needs to look something like this:
$objPHPPowerPoint->getLayout()->setDocumentLayout(['cx' => 1280, 'cy' => 700], true)
->setCX(1280, DocumentLayout::UNIT_PIXEL)
->setCY(700, DocumentLayout::UNIT_PIXEL);`
you can set width and height:
Please see this tutorial
$objPHPPowerPoint = new PHPPowerPoint();
$currentSlide = $objPHPPowerPoint->getActiveSlide();
$shape = $currentSlide->createDrawingShape();
$shape = $currentSlide->createRichTextShape();
$shape->setHeight(300);
$shape->setWidth(600);
$shape->setOffsetX(170);
$shape->setOffsetY(180);
$shape->getAlignment()->setHorizontal( PHPPowerPoint_Style_Alignment::HORIZONTAL_CENTER );
$textRun = $shape->createTextRun('Thank you for using PHPPowerPoint!');
$textRun->getFont()->setBold(true);
$textRun->getFont()->setSize(60);
$textRun->getFont()->setColor( new PHPPowerPoint_Style_Color( 'FFC00000' ) );
$objWriter = PHPPowerPoint_IOFactory::createWriter($objPHPPowerPoint, 'PowerPoint2007');
$objWriter->save(str_replace('.php', '.pptx', __FILE__));
I'm working with imagick and face some problem. I want to composite two images: image01 and image02,image01 is background image,a part of image02 composite on image01. the function just like GD's imagecopy function.
bool imagecopy( resource dst_im, resource src_im, int dst_x, int dst_y,
int src_x, int src_y,int src_w, int src_h )
Copy a part of src_im onto dst_im starting at the x,y coordinates
src_x, src_y with a width of src_w and a height of src_h. The portion
defined will be copied onto the x,y coordinates, dst_x and dst_y.
the question is: how to implement imagecopy function by Imagick?
thanks for your help.
This should do it:
//load files from source
$background = new Imagick(image01_src);
$overlay = new Imagick(image02_src);
//Crop the overlay to the required size
$overlay->cropImage ($new_width,$new_height,$x_offset,$y_offset);
//composite overlay on background
$background->compositeImage($overlay, Imagick::COMPOSITE_OVER, $margin_x, $margin_y);
//save result
$background->setImageFormat("png");
$background->writeImage(new_src);
//clean up
$background->clear();
$background->destroy();
$overlay->clear();
$overlay->destroy();
Use composite, for example:
$large_image->compositeImage($small_image, Imagick::COMPOSITE_OVER, $margin_x, $margin_y);
If you show me the source and final pictures, I can give you the exact code.
I am looking to add drop shadow to text on an image using PHP.
I am aware on how to add text to images and how some libraries allow you to add block shadowing, but I cannot see any which allow you to add a faded drop shadow.
Is this possible?
What you want is Imagick::shadowImage ( float $opacity , float $sigma , int $x , int $y )
Here's an example where I put a drop shadow on some text and then superimpose that on a background image...
$background_layer = new Imagick('poster_pic_01.jpg'); # background image
$text_layer = new Imagick('transparent400.png'); # empty transparent png of the same size
$text_layer->annotateImage( $ImagickDraw, $pad_left, $pad_top, 0, "Your text here" );
/* create drop shadow on it's own layer */
$shadow_layer = $text_layer->clone();
$shadow_layer->setImageBackgroundColor( new ImagickPixel( 'black' ) );
$shadow_layer->shadowImage( 75, 5, 5, 5 );
/* composite original text_layer onto shadow_layer */
$shadow_layer->compositeImage( $text_layer, Imagick::COMPOSITE_OVER, 0, 0 );
/* composite shadow_layer (which now has text AND the shadow) onto image_layer */
$background_layer->compositeImage( $shadow_layer, Imagick::COMPOSITE_OVER, 0, 0 );
Hope this helps,
Roger
GD can't do this out of the box. If you can, use ImageMagick. Examples on how to do shaped shadows here.
I've been looking everywhere to try and find a function to skew an image with php using the GD library. I've read threads where ImageMagick has been suggested but I unfortunately don't have access to that library on my server so I'm forced to use GD.
I'm looking for something where I can specify the source image and destination image and then 4 sets of X and Y coordinates for each corner of the image. So something like this would be ideal:
bool skewImage(resource $src_im, resource $dst_im, int $x1, int $y1, int $x2, int $y2, int $x3, int $y3, int $x4, int $y4)
If anyone has or knows of a function like this or similar that would be awesome, thanks!
The PHP manual is an amazing place. This comment pretty much covers a lot of scenarios. Use the 'Perspective' section. Below example is slightly modified to use the width and height from the image.
$image = new imagick( "grid.jpg" );
$points = array(
0,0, 80,120, # top left
$image->width,0, 300,10, # top right
0,$image->height, 5,400, # bottom left
$image->width,$image->height, 380,390 # bottum right
);
$image->setimagebackgroundcolor("#fad888");
$image->setImageVirtualPixelMethod( imagick::VIRTUALPIXELMETHOD_BACKGROUND );
$image->distortImage( Imagick::DISTORTION_PERSPECTIVE, $points, TRUE );
header( "Content-Type: image/jpeg" );
echo $image;