gd

How to check a PNG for grayscale/alpha color type?

一曲冷凌霜 提交于 2019-12-01 01:15:39
问题 PHP and GD seem to have trouble creating images from PNGs of type greyscale with alpha when using imagecreatefrompng() . The results are incredibly distorted. I was wondering if anyone knew of a way to test for the colour type in order to notify the user of the incompatibility? Example: Original Image: http://dl.dropbox.com/u/246391/Robin.png Resulting Image: http://dl.dropbox.com/u/246391/Robin_result.png Code: <?php $resource = imagecreatefrompng('./Robin.png'); header('Content-type: image

Convert JPEG to a Progressive JPEG in PHP

こ雲淡風輕ζ 提交于 2019-12-01 01:15:30
I'm trying to re-save an already created JPEG as a progressive jpg. Basically, on the front end I have some JS that crops an image, and outputs a base64 image JPEG. Once it is passed to the PHP script, I create it as a regular JPEG file, like so: $largeTEMP = explode(',', $_POST['large']); $large = base64_decode($largeTEMP[1]); file_put_contents('../../images/shows/'.$dirName.'/large.jpg', $large); I'm wanting this jpg image to be progressive, so I was looking around and found the PHP function imageinterlace ; however, I can't seem to get it to work. I've tried various combinations, but I feel

Resize image and display without saving it

五迷三道 提交于 2019-12-01 00:04:41
I've built an image gallery and saved the image "as is" without cropping it. I want to resize the image on the fly while it's loaded in the controller, so when I load the controller in the browser it displays the image re-sized to whatever I want. I've added the method to MY_Loader , here is the code. function show_image($image, $width, $height) { $this->helper('file'); $image_content = read_file($image); //resize image $image = imagecreatefromjpeg($image); $thumbImage = imagecreatetruecolor(50, 50); imagecopyresized($thumbImage, $image, 0, 0, 0, 0, 50, 50, $width, $height); imagejpeg(

PHP GD Library output an image and text content on same page

落爺英雄遲暮 提交于 2019-11-30 23:11:16
I am trying to output an image to a browser and then output HTML (not directly related to the image) on the same page. Is this possible? I am having a heck of a time figuring it out. Here is my code I have been messing with: <?php function LoadJpeg($imgname){ /* Attempt to open */ $im = @imagecreatefromjpeg($imgname); /* See if it failed */ if(!$im){ /* Create a black image */ $im = imagecreatetruecolor(150, 30); $bgc = imagecolorallocate($im, 255, 255, 255); $tc = imagecolorallocate($im, 0, 0, 0); imagefilledrectangle($im, 0, 0, 150, 30, $bgc); /* Output an error message */ imagestring($im, 1

Image upload security - reprocess with GD

瘦欲@ 提交于 2019-11-30 22:48:40
I've heard that the best way to handle uploaded images is to "re-process" them using the GD library and save the processed image. see: PHP image upload security check list My question is how do this "re-processing" in GD ? What this means exactly? I don't know the GD library very well and I'm afraid I will mess it up... So if anyone who did this before could you give me an example for this? (I know, another other option is to use ImageMagick. For ImageMagick I found an answer here: Remove EXIF data from JPG using PHP , but I can't use ImgMagick now. By the way.. removing EXIF data means

Image transparency and alpha when merging images with PHP

限于喜欢 提交于 2019-11-30 22:33:47
So I found some code on PHP Doc, and edited it slightly to merge two images I have. The image is then saved in a folder on the server. However there is a slight problem and I am unable to figure out why it is happening. Firstly my code: $glassurl = $_GET['GlassImg']; $frameurl = $_GET['FrameImg']; $filename = (int)date("H:i:s"); $src = imagecreatefromgif($frameurl); $dest = imagecreatefromjpeg($glassurl); imagecolortransparent($src, imagecolorat($src, 0, 0)); imagealphablending($dest, false); imagesavealpha($dest, true); imagealphablending($src, false); imagesavealpha($src, true); $src_x =

PHP & GD - transparent background being filled with nearby color

三世轮回 提交于 2019-11-30 20:24:21
I know PHP+GD Transparency issues have been beat to death on this and many other sites, but I've followed all the recommendations and I can't seem to fix my issue. First, the explanation: I am trying to overlay one image on top of another one. They both have areas that are transparent. As a demo that I know should look a particular way, I am trying to overlay a checkmark on top of a blue arrow shape that I created. Here are the two images: Now to my code: I am using a library/API that I built to take a TINY bit of the pain away from editing images with PHP+GD. It's still in it's infancy, but

Resize images with transparency in php

纵然是瞬间 提交于 2019-11-30 18:32:53
I have looked all over for how to correctly manage alpha when I'm resizing a png. I've managed to get it to keep transparency, but only for pixels that are completely transparent. Here's my code: $src_image = imagecreatefrompng($file_dir.$this->file_name); $dst_image = imagecreatetruecolor($this->new_image_width, $this->new_image_height); imagealphablending($dst_image, true); imagesavealpha($dst_image, true); $black = imagecolorallocate($dst_image, 0, 0, 0); imagecolortransparent($dst_image, $black); imagecopyresampled($dst_image, $src_image, 0, 0, 0, 0, $this->new_image_width, $this->new

Image transparency and alpha when merging images with PHP

依然范特西╮ 提交于 2019-11-30 18:31:04
问题 So I found some code on PHP Doc, and edited it slightly to merge two images I have. The image is then saved in a folder on the server. However there is a slight problem and I am unable to figure out why it is happening. Firstly my code: $glassurl = $_GET['GlassImg']; $frameurl = $_GET['FrameImg']; $filename = (int)date("H:i:s"); $src = imagecreatefromgif($frameurl); $dest = imagecreatefromjpeg($glassurl); imagecolortransparent($src, imagecolorat($src, 0, 0)); imagealphablending($dest, false);

Heroku - how to enable gd on heroku php application?

回眸只為那壹抹淺笑 提交于 2019-11-30 16:27:49
问题 Heroku said: The following built-in extensions have been built “shared” and can be enabled through composer.json (internal identifier names given in parentheses): But it doesn't give an example, I tried with the following composer.json: { "require": { "gd": "*" } } But when I git push heroku master , I get: My composer.json: { "require": { "gd": "*" } } But when I git push heroku master , I get: -----> Installing dependencies... Composer version 1.0.0-alpha9-19-g10401d5 2014-12-09 11:32:02