I'm resizing and saving some images using Coldfusion8. However, all images, no matter what size are blurred and I don't know how to turn it off.
This is what I'm doing:
<cfimage action="read" source="#variables.basePath#" name="base">
<cfscript>
variables.height = 127;
variables.width = "";
ImageScaleToFit(base, variables.width, variables.height);
variables.offset = ImageGetWidth( base ) - 100;
if ( variables.offset GT 0 )
{
imageCrop( base, variables.offset/2, 0, 100, 127 );
}
variables.filekey = "s_" & img_paths.bilddateiname;
variables.filename = variables.tempDirectory & variables.keyName;
imageWrite( base, variables.filename, ".99" );
</cfscript>
Any idea what I'm doing wrong? The images are blurred no matter if I convert to 800x1110px or the above 100x127. The base picture is sharp, so it must be something I'm doing when resizing.
Thanks for inputs!
EDIT:
original image:
resized image:
Using CF9.0.2
Using your source jpeg, your code, and hardcode the output to be y.jpg:
What's wrong? Isn't this what you expect?
Related
I have a 1,300 games that I'm using in a frontend. I would like to generate 'banner' images that contain the name of the game on a static background image.
Ideally I would like to parse all the names in a list or array and run some software to create the images for me.
I wondered if this was possible/practical with PHP and, if so, how I would start to go about it?
The ideal solution would be some software that takes a static background image and co-ordinates of the bounding box (i.e. an area that the text must stay within). It then takes the name to be written and adjusts the size to fit the bounding box as best as possible. It then creates the image and saves that file and starts again with the next name in the array/list.
Any thoughts on how to do this? Is it even possible?
The GD library can do this. Use the imagettfbbox() function to calculate the dimensions of text.
Here's an example that adds a left-aligned caption to the bottom of an image. If the text is too long to fit in at the specified size, the size is reduced to make it fit.
<?php
$img_src = "mona-lisa.jpg";
$txt = "Hello World";
$font = "DroidSans.ttf";
$text_size = 60.0;
$baseline_y = 30;
$margin = 20;
$img = imagecreatefromjpeg($img_src);
$width = imagesx($img);
$height = imagesy($img);
$box = imageftbbox($text_size, 0.0, $font, $txt);
$txtw = $box[2];
// If text_size is too large, adjust accordingly
if ($txtw > $width - 2 * $margin) {
$text_size *= ($width - 2 * $margin) / $txtw;
}
$white = imagecolorallocate($img, 255, 255, 255);
imagefttext($img, $text_size, 0.0, $margin, $height-$baseline_y, $white, $font, $txt);
imagejpeg($img);
Output:
Take a look at this script:
$path = 'storage/test-image.JPG';
$savePath = 'storage/test-image-saved.JPG';
$image = \Spatie\Image\Image::load(public_path($path));
$image
->height($image->getHeight()) // manipulating height to its original height
->save(public_path($savePath));
$originalSize = File::size(public_path($path)); // 1.7MB
$savedSize = File::size(public_path($savePath)); // 200KB
The result is that the image got compressed, and its colour changed. This is out of my expectation for an image manipulation tool.
Can anyone with experience care to explain it a bit?
Thank you.
I am loading a pixel font file as a png image. I then use it to draw each character to canvas by writing to the buffer imageData.data clamped array and then using putImageData.
Is there a simpler way to get the data array from the png image apart from loading the image as fontImage and then these 7 lines ...
let fontCanvas = document.createElement("canvas");
fontCanvas.width = fontImage.width;
fontCanvas.height = fontImage.height;
let fontContext = fontCanvas.getContext("2d");
fontContext.drawImage(fontImage, 0, 0);
let fontBank = fontContext.getImageData(0,0,fontCanvas.width,fontCanvas.height);
let fontData = fontBank.data;
Thanks.
I have an image that has been broken in to parts, 64 rows by 64 columns. Each image is 256x256px. The images are all PNG. They are named "Image--.png" for example "Image-3-57". The rows and columns numbering start from 0 rather than 1.
How can I assemble this back in to one image? Ideally using BASH and tools (I'm a sysadmin) though PHP would be acceptable as well.
Well, it is not very complicated, if you want to use PHP. What you need is just a few image gunctions - imagecreate and imagecopy. If your PNG is semi transparent, you will also need imagefilledrectangle to create a transparent background.
In code below, I rely on fact, that all chunks are same size - so the pixel size must be able to be divided by the number of chunks.
<?php
$width = 256*64; //height of the big image, pixels
$height = 256*64;
$chunks_X = 64; //Number of chunks
$chunks_Y = 64; //Same for Y
$chuk_size_X = $width/$chunks_X; //Compute size of one chunk, will be needed in copying
$chuk_size_Y = $height/$chunks_Y;
$big = imagecreate($width, $height); //Create the big one
for($y=0; $y<$chunks_Y; $y++) {
for($x=0; $x<chunks_X; $x++) {
$chunk = imagecreatefrompng("Image-$x-$y.png");
imagecopy($big, $chunk,
$x*$chuk_size_X, //position where to place little image
$y*$chuk_size_Y,
0, //where to copy from on little image
0,
$chuk_size_X, //size of the copyed area - whole little image here
$chuk_size_Y,
);
imagedestroy($chunk); //Don't forget to clear memory
}
}
?>
This is just a draft. I'm not sure about all theese xs and ys as well as ather details. It is late and I'm tired.
I am getting image containing character after applying my image process. All these images (having character as content) have different size. I want to resize all images in same size without effecting it's content size. see below image:
http://techsture.com/img.jpg
I have tried some function to merge my source image with other white image but it needs both source images with same size. I need common size of images for further process.
Please guide me how can I convert my images to common size ??
Thank you
I would make a new image with the destination size, set a ROI in this new image to where you want the source image to show. Then use cvResize.
It should look something like:
int newWidth = 100;
int newHeight = 100;
CvRect rect;
IplImage* source = cvLoadImage("c:/myimage");
IplImage* dest = cvCreateImage(cvSize(newWidth,newHeight),source->depth,source->nChannels);
rect.x = newWidth/2 - source->width/2;
rect.y = newHeight/2 - source->height/2;
rect.width = source->width;
rect.height = source->height;
cvSetImageROI(dest,rect);
cvResize(source,dest);
cvResetImageROI(dest);