gd

Resize then crop PHP

ぃ、小莉子 提交于 2019-12-04 12:39:28
Ok, basically I want all images to be 170x170px squares. Thus if an image is not a square i want it to be resized, and then cropped in the middle.. I have spent numerous hours playing with this and I am getting nowhere.. I have gotten it to crop a section of the bigger image etc, but i specifically need the image to be resized, then cropped.. Any help would be greatly appreciated. // get image size of img $x = @getimagesize($img); // image width $sw = $x[0]; // image height $sh = $x[1]; if($sw > $sh) // Horizontal Rectangle? { $newwidth = ($sw/$sh)*170; $newheight=170; $x_pos = ($sw - $sh) / 2

PHP Thumbnail Class

拟墨画扇 提交于 2019-12-04 12:26:19
问题 I am looking for a solid PHP thumbnail generating class. Does anyone know any good ones that are open-source? I could write one, but I really don't want to. The one thing I hate most about PHP is manipulating images with GD and Imagemagick. Does anyone have any suggestions? 回答1: Use phpThumb(). Its a script that internally uses GD library and/or ImageMagick (whichever is available and whichever it thinks is best for the job) to perform basic image manipulation tasks, including thumbnail

imagettftext function using font from remote server

强颜欢笑 提交于 2019-12-04 12:19:34
I am creating an image form font size, font family, font color in php. Everything was working fine until I got a new requirement. I was using ttf files and passing the path of particular ttf file in imagettftext function as a parameter. Now I am using google fonts and I am not getting an idea how to get the font in my function. I tried using couple of things such as passing 1.http://fonts.googleapis.com/css?family=Tangerine<br/> 2.http://themes.googleusercontent.com/static/fonts/abel/v3/RpUKfqNxoyNe_ka23bzQ2A.ttf But not getting any thing. first download the ttf file $font = file_get_contents(

how to detect shape in a image with php?

只愿长相守 提交于 2019-12-04 09:53:02
I have to detect 'star' like shape in a image with php.Also the star is not fixed and may be at other position next time.I cannot use any external software or library.I have tried all methods like edge detection and grayscaling but all in vain.this is the image: the main problem is I cannot clear the background. if image background is cleared than i can read all pixels color row wise as well as column wise and detect.please help me.this is the image after brightness_filter and edge detection. For this particular image would suggest to perform a low amount of lowpass filtering (Gaussian blur)

Troubles with Docker + PHP7 + GD resulting in “Call to undefined function imagecreatefromjpeg()”

流过昼夜 提交于 2019-12-04 08:29:54
问题 I'm having troubles when trying to create an image using imagecreatefromjpeg using this Dockerfile to generate the container: FROM php:7.1-apache RUN apt-get update && \ apt-get install -y -qq git \ libjpeg62-turbo-dev \ apt-transport-https \ libfreetype6-dev \ libmcrypt-dev \ libpng12-dev \ libssl-dev \ zip unzip \ nodejs \ npm \ wget \ vim RUN pecl install redis && docker-php-ext-enable redis RUN docker-php-ext-install -j$(nproc) iconv mcrypt zip pdo pdo_mysql gd bcmath COPY ./containers

What's the math behind CSS's background-size:cover

吃可爱长大的小学妹 提交于 2019-12-04 07:46:08
问题 I'm creating an "image generator" where users can upload an image and add text and/or draw on it. The outputted image is a fixed size (698x450). On the client side, when the user uploads their image it is set as the background of a div that's 698x450 with background-size:cover. This makes it fill the area nicely. The final combined image is generated by PHP using GD functions. My question is, how can I get the image to scale in PHP the same way it does in CSS. I want the result of the PHP

Resize image size according to size of text

家住魔仙堡 提交于 2019-12-04 07:22:47
The PHP code below generates text as a dynamically created image, how would I be able to get the image to only be as large as the text? Thanks. <?php header('Content-Type: image/jpeg'); $text='Test'; $img = imageCreate(200,200); imagecolorallocate($img, 255, 255, 255); $textColor = imagecolorallocate($img, 0, 0, 0); imagefttext($img, 15, 0, 0, 55, $textColor, 'bgtbt.ttf', $text); imagejpeg($img); imagedestroy($img); ?> UPDATE 1: I found the answer here with the example of the original poster - Creating IMage from Text in PHP - how can I make multiline? UPDATE 2: Martin Geisler's version also

imagecreatefrompng error

女生的网名这么多〃 提交于 2019-12-04 06:35:46
问题 <?php function LoadPNG($imgname) { /* Attempt to open */ $im = @imagecreatefrompng($imgname); /* See if it failed */ if(!$im) { /* Create a blank 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, 5, 5, 'Error loading ' . $imgname, $tc); } return $im; } header('Content-Type: image/png'); $img = LoadPNG('http://www

How to loop through all the pixels of an image?

依然范特西╮ 提交于 2019-12-04 06:17:38
I want to loop through all the pixels of an image, find the rgba value of that pixel, and do something with those pixels. Example Say I have an image that's 100x100 pixels. I want to find the value of each one of those pixels with the function I already made: function getPixel($image, $x, $y) { $colors = imagecolorsforindex($image, imagecolorat($image, $x, $y)); $inrgba = 'rgba(' . $colors['red'] . ',' . $colors['green'] . ',' . $colors['blue'] . ',' . $colors['alpha'] . ')'; return $inrgba; } And store those values, along with the dimensions of the image, in an array, or an array of arrays. I

Perspective transformation with GD

不羁的心 提交于 2019-12-04 05:42:52
How can I apply a perspective transformation on an image using only the PHP GD library? I don't want to use a function someone else made I want to UNDERSTAND what's going on I honestly don't know how to describe mathematically a perspective distortion. You could try searching the literature for that (e.g. Google Scholar ). See also in the OpenGL documentation, glFrustum . EDIT : Interestingly, starting with version 8, Mathematica has a ImagePerspectiveTransformation . In the relevant part, it says: For a 3*3 matrix m , ImagePerspectiveTransformation[image,m] applies LinearFractionalTransform[m