I have an image that is 180x240 and I want to pad/border it with white until it fits the size 360x240, so the original content from image won't get distort.
http://www.magickwand.org/ - I can't find any suggestive function in the documentation
I do not use Magickwand but with Imagemagick there is an operator called extent which does what you want. But I can not see any mention of extent in the documentation you linked.
You may have to create a white canvas of 360x240 and composite your image onto it.
Alternativly could you use MagickBorderImage and have the border set to 0 or 1 on the height and 90 on the width?
Related
In Imagick, when i use "negateImage" in images with alpha channel (png), the transparency is not well handled by imagick. I want to keep the transparency, only negate the "colored" pixels.
Origin image
Desired image
How can i do it?
Try specifying the specific channels that you want to negate:
$imagick->negateImage(false, imagick::CHANNEL_RED | imagick::CHANNEL_GREEN | imagick::CHANNEL_BLUE);
The above assumes an RGB image.
I did found a topic similar to this, but I do not know if the solution is the same. So here is my question:
I'm using the GD functions to bild a web card generating program. The thing is that the card's backgound is generating by the $image = imagecreatefrompng(); function.
The card need's also a $cardname as "title" and a $desription as desription. For that I used the imagettftext(); function. But there is a problem, the card's size is 333x485, I need the text to be resized in order to fit in the background without resizing its height, but only the width!
To be more to the point, the $cardname should have width = 240 and height = 34, but if it doesn't fit, it goes off the background, I need a function that will resize its width in order to fit in 240px and leave the height to 34px always!
To understand it more look here: http://yugiohcardmaker.net. in the "name" you can add as much text you like, it will always fit in and in the right width and height!
I'm not going to try and code this as it will take too long, but here's the basic process:
Get the size of the bounding box for your text with imagettfbbox();
Create a new image with imagecreatetruecolor();
Write your text into your new image with imagettftext();
Use imagecopyresampled() to copy the new image with your text to your existing card, setting the parameters to shrink the width but not the height.
Note: the bounding box parameters returned by imagettfbbox()) can be fiddly to work with
You'll also need to be careful about alphablending and background colors to ensure that only your text pixels are copied.
Good luck!
I often see some websites using the below code to resize image size.
?w=250
?w=150
?w=75
?w=50
Sample:
http://domain.com/customthumb/2013/08/07/72/getty380.jpg?w=250
http://domain.com/customthumb/2013/08/07/72/getty380.jpg?w=150
http://domain.com/customthumb/2013/08/07/72/getty380.jpg?w=75
http://domain.com/customthumb/2013/08/07/72/getty380.jpg?w=50
I already search in Google, but I can't find the solution.
Do you know how to do it in PHP?
This is the demo:
Original size don't using "?w=75" or other size:
_http://images.detik.com/customthumb/2013/08/09/722/uang4depan.jpg
width 75px : _http://images.detik.com/customthumb/2013/08/09/722/uang4depan.jpg?w=75
width 100px : _http://images.detik.com/customthumb/2013/08/09/722/uang4depan.jpg?w=100
width 110px : _http://images.detik.com/customthumb/2013/08/09/722/uang4depan.jpg?w=110
width 150px : _http://images.detik.com/customthumb/2013/08/09/722/uang4depan.jpg?w=150
Note: remove underscore "_" in front of URL.
I don't know what those URLS are for, but many PHP users use the Imagick functions to manipulate images.
There are several ways, considering what's your output.
First of all, HTML can do this so if you use
print "<img src='...whatever...' width='$x'>"
this will do the trick. Now if you're writing with a header like image/jpg, which means you're being called from an IMG tag and your script returns the image itself - well, use GD library and imagecopyresampled(). But that's a thing I'll explain in detail only if you really need it.
How do i resize image preserving its dimension ratio proportion and transparancy in php
Use the GD library from MicroMVC. It's the smallest, fastest GD lib out there.
The function you want is called imagecopyresampled(); don't forget to only use true color images for destinations. Here is a comment which talks specifically about preserving transparency: http://www.php.net/manual/en/function.imagecopyresampled.php#93166 (note the usage of the imagecolorallocatealpha() function)
I'm trying to create an image with varying level of transparency, using GD. But I can get only fully transparent or fully opaque pixels in the image.
What I want to get: What I actually get:
(source: bx.at.ua)
(source: bx.at.ua)
(source: bx.at.ua)
(source: bx.at.ua)
Here's a piece of the code I used to create images like this one ▲ fixed code:
$im=imagecreatetruecolor($sx,$sy);
imageantialias($im,true);
imagesavealpha($im,true);
$c00FF00=imagecolorallocate($im,0,255,0);
$cFFFFFF=imagecolorallocate($im,255,255,255);
$cFFFFFF_00=imagecolorallocatealpha($im,255,255,255,127);
imagecolortransparent($im,$cFFFFFF);
imagefilledrectangle($im,0,0,$sx,$sy,$cFFFFFF$cFFFFFF_00);
$sim=imagecreatefrompng('gradient.png');
imagecopy($im,$sim,$dest_x,$dest_y,0,0,imagesx($sim),imagesy($sim));
imagedestroy($sim);
imagettftext($im,$size,0,$text_x,$text_y,$c00FF00,$font,'Test');
header('Content-type: image/png');
imagepng($im);
imagedestroy($im);
What can I do to get the desired (translucent) result?
You need to call imagesavealpha() against your imported PNG ($sim) before merging, as well as against the final image.
What you are looking for is not transparency but alpha. Alpha is another color channel that goes along with the red, green and blue colors to determine the transparency level (just transparent is visible or not as opposed to being able to set the level of transparency). Check out imagecolorallocatealpha