gd

Trying to generate proportionally cropped thumbnails at a fixed width/height with PHP GD

空扰寡人 提交于 2019-12-20 03:49:07
问题 I'm trying to create a Thumbnail Generator in PHP with GD that will take an image and reduce it to a fixed width/height. The square it takes from the original image (based on my fixed width/height) will come from the center of the image to give a proportionally correct thumbnail. I'll try to demonstrate that confusing sentence with some nice ASCII :} LANDSCAPE EXAMPLE: XXXXXXXXXXXXXXXX XXXXOOOOOOOOXXXX XXXXOOOOOOOOXXXX XXXXOOOOOOOOXXXX XXXXOOOOOOOOXXXX XXXXXXXXXXXXXXXX XXXXXXXX XXXXXXXX

Does html can be use with dynamic generated images in php?

时光毁灭记忆、已成空白 提交于 2019-12-20 02:38:04
问题 I am using this code to create an image <?php // Set the content-type header('Content-Type: image/png'); // Create the image $im = imagecreatetruecolor(400, 30); // Create some colors $white = imagecolorallocate($im, 255, 255, 255); $grey = imagecolorallocate($im, 128, 128, 128); $black = imagecolorallocate($im, 0, 0, 0); imagefilledrectangle($im, 0, 0, 399, 29, $white); // The text to draw $text = 'Testing...'; // Replace path by your own font path $font = 'arial.ttf'; // Add some shadow to

Resizing with GD outputs black images

自闭症网瘾萝莉.ら 提交于 2019-12-19 12:23:52
问题 What can cause php gd to produce a black image after resizing? The following code always outputs a black image for every valid jpeg file. <?php $filename = 'test.jpg'; $percent = 0.5; header('Content-Type: image/jpeg'); list($width, $height) = getimagesize($filename); $newwidth = $width * $percent; $newheight = $height * $percent; $thumb = imagecreatetruecolor($newwidth, $newheight); $source = imagecreatefromjpeg($filename); imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight,

PHP/GD ImageSaveAlpha and ImageAlphaBlending

让人想犯罪 __ 提交于 2019-12-19 09:06:32
问题 I'm using GD to resize and convert images, however during my tests I found a weird behavior when converting transparent PNG's to JPEG's. According to the manual ImageAlphaBlending() is on by default but in order to preserve the transparency I must set ImageSaveAlpha() to true (which in turn requires that I set ImageAlphaBlending() to false). So the correct way should be: $result = ImageCreateFromPNG(...); ImageAlphaBlending($result, false); ImageSaveAlpha($result, true); ImageFill($result, 0,

move_uploaded_file doesn't work, no error

你离开我真会死。 提交于 2019-12-19 06:30:08
问题 I am running running a script which moves an uploaded file with move_uploaded_file() . I have done this thousands of times but for some reason it's not working. I have confimred the following: <form> using method="post" and correct enctype correct file referenced from form directory has permissions 777 all the memory_limit , max_execution_time , etc are set to super high settings to avoid timeouts Basically, the script below returns with just Your image is too big. . I have also enabled ALL

PHP GD how to draw text over a line

筅森魡賤 提交于 2019-12-19 06:20:42
问题 The final output should be like image(HELLO WORLD): Here is what i am doing:- $im = imagecreate(400,400); $txtcol = imagecolorallocate($im, 0xFF, 0x00, 0x00); $size = 20; $txt = 'DUMMY TEXT'; $font = './font/Capriola-Regular.ttf'; /*two points for base line*/ $x1 = 50; $x2 = 300; $y1 = 150; $y2 = 170; /*bof finding line angle*/ $delta_x = $x2-$x1; $delta_y = $y2-$y1; $texangle = (rad2deg(atan2($delta_y,$delta_x)) * 180 / M_PI)-360; /*eof finding the line angle*/ imageline($im,$x1,$y1,$x2,$y2,

image collage in PHP

喜夏-厌秋 提交于 2019-12-18 13:19:23
问题 I'm looking for a finshed solution or possibly some math/algorithms for creating a big image collage out of smaller product pictures? I know how to do it in a square fashion, from same sized pictures with gd/imagemagick but I'd like to have some variation built in. For example, some of the pictures might be slightly taller, and if all are the same size and square - i might want 1 of them take up more space, just to mix up the design. keeping it interesting. the more i think about this the

Create a picture with GD containing other images

旧巷老猫 提交于 2019-12-18 12:47:08
问题 I would like to create a picture in PHP with GD composed by different other pictures. For example I have 6 pictures (or more) and I would like to create ONE picture who contain these different pictures. The Difficulty is that my final picture must have a fixed width and height (304x179), so if the different pictures are too big they must be cut. This is an example from IconFinder : This picture is composed by 6 images, but the 3rd bird (green) is cutted, and the 4, 5 and 6 are cutted in the

Enabling/installing GD extension? --without-gd

点点圈 提交于 2019-12-18 12:45:10
问题 How does one enable (or perhaps I need to install) GD when my phpinfo() output in "Configure Command" says; --without-gd ? I also have nothing in my phpinfo() output "Core" that lists "gd" PHP Version 5.2.4 on AWS. 回答1: if you are on a Debian based server (such as Ubuntu) you can run the following command: apt-get install php5-gd Then once it is complete run: /etc/init.d/apache2 restart This will restart your server and enable GD in PHP. If you are on another type of system you will need to

Use PHP to convert JPEGs to transparent PNG

本小妞迷上赌 提交于 2019-12-18 12:06:43
问题 I have a lot of JPEG images that I want to convert to PNG images using PHP. The JPEGs are going to be uploaded by clients so I can't trust them to make sure they are in the right format. I also want to make their white backgrounds transparent. Does PHP have any functions I can use to achieve this? 回答1: After a few days of trying different solutions and doing some more research, this is what I found worked for me. $image = imagecreatefromjpeg( 'image.jpg' ); imagealphablending($image, true);