gd

PHP JPEG Functions Not Working

这一生的挚爱 提交于 2019-12-31 03:28:25
问题 Any PHP functions that deal with JPEGs don't seem to be working on my server. This code: <?php $im = imagecreatetruecolor(120, 20); $text_color = imagecolorallocate($im, 233, 14, 91); imagestring($im, 1, 5, 5, 'A Simple Text String', $text_color); header('Content-type: image/jpeg'); imagejpeg($im); imagedestroy($im); ?> creates an empty file. Using a GIF or PNG function will create an image containing the text "A Simple Text String" as expected. This: $im = imagecreatefromjpeg("test.jpg");

How to include an image inside another image in PHP?

谁说我不能喝 提交于 2019-12-31 01:06:08
问题 How to include an image inside another image in PHP? I want to do it like in twitterbackgrounds.com personalized backgroud. there is one main image and we can upload four personal images after that it will show as watermark of the main image. 回答1: Well, there are several possibilies to do that. The one that pops into my mind is to use a php page where you can upload all files needed for this. After submission you can use imagemagick to create the new image with watermarks and display it on

Max crop area for a given image and aspect ratio

情到浓时终转凉″ 提交于 2019-12-30 11:25:11
问题 Is there any PHP/GD function that can calculate this: Input: image width, image height and an aspect ratio to honor. Output: the width/height of the max centered crop that respects the given aspect ratio (despite image original aspect ratio). Example: image is 1000x500, a.r. is 1.25: max crop is 625x500. image is 100x110, max crop is: 80x110. 回答1: There is no function that calculates this because it's elementary math: $imageWidth = 1000; $imageHeight = 500; $ar = 1.25; if ($ar < 1) { // "tall

Want to render an image without saving it to disk using PHP GD libs

假如想象 提交于 2019-12-30 10:47:05
问题 Hi have the following function function renderBusinessCard($details){ //Getting the template for the business card $filename = Templates::model()->getTemplateFileName($details['BusinessCards']['dp_id']); header("Content-type: image/jpeg"); $image = $_SERVER['DOCUMENT_ROOT'].'resources/templates/'.$filename; // header("Content-Type: image/jpeg"); //Getting the width and height of the image list($width,$height) = getimagesize($image); //echo $width;die; //Creating a copy of a loaded image

How does “imagettfbbox()” in PHP work?

那年仲夏 提交于 2019-12-30 08:15:14
问题 Could you please explain what exactly the return value of imagettfbbox() mean? The manual says: imagettfbbox() returns an array with 8 elements representing four points making the bounding box of the text on success and FALSE on error. [...Table of points here...] The points are relative to the text regardless of the angle, so "upper left" means in the top left-hand corner seeing the text horizontally. But, I found it not very clear. For example, the return value: array(-1, 1, 61, 1, 61, -96,

Adding one image at the bottom of another in PHP

主宰稳场 提交于 2019-12-30 03:42:10
问题 I'd like to add one image to the bottom of another in php I've this to load the images: //load top $top = @imagecreatefrompng($templateTop); //load bottom $bottom = @imagecreatefrompng($templateBottom); Now I'd like to add them to one picture and display top and bottom together. What way can I do this? Thanks! 回答1: Use imagecopy: $top_file = 'image1.png'; $bottom_file = 'image2.png'; $top = imagecreatefrompng($top_file); $bottom = imagecreatefrompng($bottom_file); // get current width/height

A fail-safe way to prevent GD image library from running out of memory? (PHP)

怎甘沉沦 提交于 2019-12-30 03:24:07
问题 Is there a way to prevent the PHP GD image library from running out of memory? If too large an image is uploaded, GD tends to run out of memory, terminating the script. I'd like it to throw a catchable exception or something to that extend, but alas it doesn't. Right now I'm using a cobbled-together script that first issues an ini_set('memory_limit', '128M') , if that works I'm usually all set. Depending on the server configuration though that may not be possible, so I'm falling back on an

Generate image from html with php

我的梦境 提交于 2019-12-29 08:34:19
问题 For some security reasons, I would like to generate an image based on Google Calendar embed iframe, to be able to show it on a website who don't allow iframes. Is there any php library to create an image from html? The script have to be executable on a linux server. 回答1: The library wkhtmltoimage works perfectly. I have created a page to embed the google calendar (the url can't be reach directly). I generate a picture from this page and I link this image on my profile on the website. Thanks

Generating image thumbnails using php - without running out of memory

为君一笑 提交于 2019-12-29 08:21:40
问题 I am currently using a php gd implementation to resize images which constantly runs out of memory - rather quickly. I guess the problem are the php functions, like imagecreatefromstring etc. Is there an easy implementation to resizing images which doesn't use this functions, so I won't have to increase my php.ini memory limit? 回答1: GD don't use that much memory, so you have other problems in your code. If you resize multiple images and don't call imagedestroy on a newly created image, you run

Why does this transparent PNG cause borders when combined using GD?

有些话、适合烂在心里 提交于 2019-12-29 07:42:34
问题 I am trying to create an image from an another image using PHP. Here is my code: <?php $width = 109; $height = 109; $image = imagecreatetruecolor($width, $height); $source_under = imagecreatefrompng('ecloid_under.png'); $black = imagecolorallocate($image, 0x00, 0x00, 0x00); imagecolortransparent($image, $black); imagecopy($image, $source_under, 0, 0, 0, 0, $width, $height); header('Content-type: image/png'); imagepng($image); imagedestroy($image); ?> So I am loading this image in $source