gd

Get remote image using cURL then resample

我与影子孤独终老i 提交于 2019-12-07 02:55:04
问题 I want to be able to retrieve a remote image from a webserver, resample it, and then serve it up to the browser AND save it to a file. Here is what I have so far: $ch = curl_init(); // set URL and other appropriate options curl_setopt($ch, CURLOPT_URL, "$rURL"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HEADER, 0); // grab URL and pass it to the browser $out = curl_exec($ch); // close cURL resource, and free up system resources curl_close($ch); $imgRes =

PHP GD - Transparent areas goes black

◇◆丶佛笑我妖孽 提交于 2019-12-07 02:51:52
问题 I am trying to make very simple ISO engine in PHP, my attempts to render in correct place, order etc are succeding however the images drawn, for some reason are black where it should be transparent. PNG files have transparency channel and I am using following test code: http://pastebin.com/TXk4LkJ8 The code is just rough draft. Files are just 3 faces of an block with dimensions as follows: top - 44x22; sides:23x34 Thank you for your help and I hope the question is clear enough. Edit: Here is

Take a thumbnail from a quicktime (movie) file

为君一笑 提交于 2019-12-07 00:45:23
问题 Does someone know if it's even possible (in PHP) to take a frame/thumbnail from a quicktime movie on the server? Something like the usual GD thumbnail generation, but for .mov files. note: I'm using dreamhost, so I don't have more than web-panel access to the server. 回答1: Dreamhost provides a shared ffmpeg binary in /usr/bin/ffmpeg, so you should definitely be able to call ffmpeg from php by using the system() or shell_exec() functions. The Dreamhost wiki has also an entry providing

php imagecopyresampled adds black background

試著忘記壹切 提交于 2019-12-06 23:44:17
问题 I have a resize image script that takes a 130x81 image and adds it to a 130x130 image, when the imagecopyresampled function runs it adds a black background into the space that is left over, even though the base image is white. Code below, I could really appreciate some help. The image I am trying to merge onto the 130x130 file php created is: $width = 130; $height = 130; $filename = 'process-add.jpg'; //130x81px jpg $this->_image = imagecreatefromjpeg($filename); $background =

Resize PNG image in PHP

China☆狼群 提交于 2019-12-06 18:45:19
问题 I'm getting a no image display when resizing PNG however the following code works for JPEG. list($width_orig, $height_orig) = getimagesize( $fileName ); $ratio_orig = $width_orig/$height_orig; if ($width/$height > $ratio_orig) { $width = $height*$ratio_orig; } else { $height = $width/$ratio_orig; } // Resample $image_p = imagecreatetruecolor($width, $height); if( $type )){ switch( $type ){ case 'image/jpeg': $image = imagecreatefromjpeg($fileName); imagecopyresampled($image_p, $image, 0, 0, 0

Why does my Image stretch when I crop it?

橙三吉。 提交于 2019-12-06 16:48:08
I am using the following code snippet in order to crop a image? function crop($width,$height) { $new_image = imagecreatetruecolor($width, $height); imagecopyresampled($new_image, $this->image, 0, 0, 0, 0, $this->getWidth(), $this->getHeight(), $width, $height ); $this->image = $new_image; } Here, $this->image is the original image $this->getWidth() and $this->getHeight() holds the original dimensions of the picture, where as $width and $height , is the crop area. But for some reason, the crop image is resized(we can almost say it is resized). How to fix this? Well, the problem is giving the

PHP Isometric cube with GD

雨燕双飞 提交于 2019-12-06 16:29:39
问题 I need to create something like this with PHP and GD: The three visible faces will be three parts of the same image, of which I know the coordinates. I suppose that this can be done with image transformations and some maths. The rotation of the cube will be always the same. I don't need "stroke" edges and face lighting like in that picture, I just need a "shadeless" cube. Finally, the result should be an alpha-transparent PNG. P.S. I only have GD on my host, I don't have access to ImageMagick

PHP+GD creating random black thumbnails

落花浮王杯 提交于 2019-12-06 16:04:00
This function is creating some random black images like.. 10% of the time, is not much, but.. you know.. shouldnt be happening. class ImgResizer { private $originalFile = ''; public function __construct($originalFile = '') { $this -> originalFile = $originalFile; } public function resize($newWidth, $targetFile) { if (empty($newWidth) || empty($targetFile)) { return false; } $src = imagecreatefromjpeg($this -> originalFile); list($width, $height) = getimagesize($this -> originalFile); $newHeight = ($height / $width) * $newWidth; if ($newHeight<'335') { //$newHeight='335'; } $tmp =

Perl GD Check If Pixel is Transparent

耗尽温柔 提交于 2019-12-06 15:48:43
I've been trying to solve this for a while. I have to check if a given pixel(x,y) is fully transparent. 1.How to Extract the alpha channel from a given pixel? Having an alpha channel of 127 will mean that the pixel is transparent? 2. I have tested the following code on a transparent pixel and It produces an RGB combination of a really dark(almost black) colour. I could use this as indicator, but I need a more accurate way. my $myImage = newFromPng GD::Image($path); $myImage->saveAlpha(1); my $index = $myImage->getPixel($x,$y); my ($red,$green,$blue) = $myImage->rgb($index); DanielLazarov I

Center text on image using PHP GD

流过昼夜 提交于 2019-12-06 15:09:51
So I am creating a banner generator. I will be adding text in the middle, but would like it to be exactly in the center. I know that imagettftext can be used to write onto the banner, but that won't center it. A likely solution could be to find the width of the text and then use half of it taken away from half of the banner width, but I've got no idea about how to do this. I am using PHP-GD and do not want to use anything else I will have to install. imagettftext($img, 14, 0, (468 - ((strlen($_GET['description']) * imagefontwidth(imageloadfont('minecraft.ttf'))) / 1)), 85, imagecolorallocate(