gd

Get image mimetype from resource in PHP/GD?

不打扰是莪最后的温柔 提交于 2019-11-27 16:41:58
问题 I'm trying to find the mime type of an image. PHP has the function getimagesize but that only takes a filename, whereas I have an image "resource" instead - i.e. an image created from imagecreatefromstring . I found the functions imagesx and imagesy which return the width/height from a resource but I can't find any function that tell me the mime type from a resource. Anyone know of a way to do this? Note: Due to a weird server set up, we can't read/write files from the server normally, only

Using a transparent PNG as a clip mask

☆樱花仙子☆ 提交于 2019-11-27 16:26:02
问题 Is it possible to take this image: And apply this mask: And turn it into this: Using either GD or Imagick? I know it's possible to mask an image using shapes but I'm not sure how to go on about doing it with a pre-created alphatransparent image. :s 回答1: Using Imagick and ImageMagick version > 6 (I don't know if it will work on older versions): // Set image path $path = '/path/to/your/images/'; // Create new objects from png's $dude = new Imagick($path . 'dude.png'); $mask = new Imagick($path

Working with GD ( imagettftext() ) and UTF-8 characters

余生长醉 提交于 2019-11-27 16:03:53
Just for the record - my first question here but hopefully not my last input in the community. But that's not why I'm here. I'm currently developing a simple system that has to generate an image with a text on it. Everthing went well until I realised that GD cannot handle UTF-8 characters like ā, č, ž, ä, ø, é and so on. To clear things up - I'm using imagettftext() Trying to solve my problem I dug into depths of google and some solutions were returned, none of them, sadly, solved my problem completely. Currently I'm using this script I found in this thread - PHP function imagettftext() and

How to achieve a blur effect in PHP?

感情迁移 提交于 2019-11-27 15:23:46
问题 I've been looking for PHP code to apply a Gaussian blur to images. What I've done was like this: <?php $image = imagecreatefromjpeg('new.jpg'); imagefilter($image, IMG_FILTER_GAUSSIAN_BLUR); imagejpeg($image, 'blur.jpeg'); imagedestroy($image); ?> However the effect is very weak, and if I repeat the blur effect, it takes a very long time to process and the end result is still not that good. I also used Timthumb , I always liked its simplicity, but it crops the image by default and its

Getting imagegrabscreen to work

Deadly 提交于 2019-11-27 14:33:31
I'm trying to get imagegrabscreen (a GD function) to work with my Apache/Vista PC. I'm using the following code: <?php $im = imagegrabscreen(); header('Content-type: image/png'); imagepng($im); imagedestroy($im); ?> At the moment I get a solid black image, the size of my secondary monitor (1024*768). I'm using Apache 2.2, runing as a service, Vista SP1 with UAC off, PHP 5.2.8 and GD (information below). I've followed the note on the imagegrabscreen page about allowing Apache access to the desktop. I've also restarted the service and the apache server. I get the same results with

Resize image before uploading PHP

核能气质少年 提交于 2019-11-27 14:15:35
问题 I have no idea how to resize image in PHP, my code is: for ($index = 1; $index <= 2; $index++) { if (!empty($_FILES["pic$index"]["name"])) { $ext = substr($_FILES["pic$index"]["name"], strrpos($_FILES["pic$index"]["name"], '.') + 1); $dir = "../gallery/$mkdir"; HERE I NEED THE RESIZE OF THE TMP FILE OF IMAGE move_uploaded_file($_FILES["pic$index"]["tmp_name"] , "$dir/img-$index.$ext"); } } $mkdir = the name of the gallery's folder (there are many galleries). $dir = where the pics will be

Merge two images in php

廉价感情. 提交于 2019-11-27 14:14:26
I have two images I would like to merge then save to a new location. I would like the second image to be place directly below the first image. I have the following so for but the image doesn't even save. $destimg = imagecreatefromjpeg('images/myimg.jpg'); $src = imagecreatefromgif('images/second.gif'); // Copy and merge imagecopymerge($destimg, $src, 316, 100, 0, 0, 316, 100, 100); Both images have a width or 316px X 100px From the above code the $destimg should now be 316x200 but that doesn't happen. Also like it to be a new image and save to another folder. Thanks for any help. The best

Can I swap colors in image using GD library in PHP?

我的梦境 提交于 2019-11-27 14:04:18
I got the image like this (it's a graph): (source: kitconet.com ) I want to change the colours, so the white is black, the graph line is light blue, etc.. is it possible to achieve with GD and PHP? This will replace the white color with Gray $imgname = "test.gif"; $im = imagecreatefromgif ($imgname); $index = imagecolorclosest ( $im, 255,255,255 ); // get White COlor imagecolorset($im,$index,92,92,92); // SET NEW COLOR $imgname = "result.gif"; imagegif($im, $imgname ); // save image as gif imagedestroy($im); David Crowell I had trouble making this solution work. The image cannot be a true

PHP/GD - transparent background

我只是一个虾纸丫 提交于 2019-11-27 12:12:00
I want to do the following in PHP in combination with GD. ImageMagick is not an option, unfortunately, but this seems like such a common problem that there has to be a solution, I just can't seem to find it. I want to create a PNG with a transparent background. Then I want to draw a rectangle on it, copy an image on it, and add some text. One way of doing this is as follows: $image = ImageCreateTrueColor (800, 600); imagecolortransparent ($image, 0); //0 is pure black, the default fill color imagerectangle (...); //code to copy an image imagettftext ($image, ...); imagepng ($image); This works

I have a base64 encoded png, how do I write the image to a file in PHP?

做~自己de王妃 提交于 2019-11-27 11:47:08
What's the proper way in PHP to create an image file (PNG), when I have the base64 encoding? I've been playing around with: file_put_contents('/tmp/'. $_REQUEST['id'].'.png', $_REQUEST['data']); do I need to decode? should I be using the gd library? My best guess is that you simply need to call base64_decode() on $_REQUEST['data'] before writing it to the file. That should be plenty enough :). You need to use base64_decode(). AND. Sometimes it is not sufficient. Here is all code that you need: $img = $_POST['data']; $img = str_replace('data:image/png;base64,', '', $img); $img = str_replace(' '