I have a google image: http://lh3.googleusercontent.com/YCHiHLv3pCrzi1dK4CFPMkyxPddG8qjsjez-ufiqthPhnqI5XIG39xuXPp0H4Di1BZk-RrIiAyb1nhUOGlA
Tried resize this image by add the "s=PixelValue" in the end of URL.
Example :
http://lh3.googleusercontent.com/YCHiHLv3pCrzi1dK4CFPMkyxPddG8qjsjez-ufiqthPhnqI5XIG39xuXPp0H4Di1BZk-RrIiAyb1nhUOGlA=s100 -> worked
http://lh3.googleusercontent.com/YCHiHLv3pCrzi1dK4CFPMkyxPddG8qjsjez-ufiqthPhnqI5XIG39xuXPp0H4Di1BZk-RrIiAyb1nhUOGlA=s200 -> worked
http://lh3.googleusercontent.com/YCHiHLv3pCrzi1dK4CFPMkyxPddG8qjsjez-ufiqthPhnqI5XIG39xuXPp0H4Di1BZk-RrIiAyb1nhUOGlA=s300 -> worked
But from s=600 :
http://lh3.googleusercontent.com/YCHiHLv3pCrzi1dK4CFPMkyxPddG8qjsjez-ufiqthPhnqI5XIG39xuXPp0H4Di1BZk-RrIiAyb1nhUOGlA=s600 -> Google return wrong image, it's different image but same URL
Related
I have an image (a strange image, but the marks in the corner just help me determine where the corners are):
However when I create a PDF using PDFKit, I get this (a print preview of the A5 PDF it generates):
The image is originally from a HTML canvas (w: 1000px, h: 709px), I do the following:
const canvasImage = canvas.toDataURL('image/png');
and send it to the backend. In the backend I do this:
const pdfDoc = new PDFDocument({
// autoFirstPage: false,
layout: 'landscape',
size: 'a5'
});
// const img = pdfDoc.openImage(base64Image);
// pdfDoc.addPage({size: [img.width, img.height]});
pdfDoc.image(base64Image, 0, 0, {align: 'center', width: 2480, height: 1748});
pdfDoc.pipe(awsUpload(`order-${orderNumber}.pdf`));
pdfDoc.end();
I have tried all sorts of variations on the image size, but it always makes it much much bigger than the A5 itself.
I have even tried converting it to 300dpi on the frontend using shuttershock's changeDPI function
const canvasImage = canvas.current.toDataURL('image/png');
const canvasImage300Dpi = changeDpiDataUrl(canvasImage, 300);
Still no luck :(.
How do I get the dimensions of the image to fit within the A5 pdf?
You are using a hardcoded image size.
Use your A5 size [419.53, 595.28] as your image width. In your case I would say: 595.28
Don't use height to scale proportional.
so i made a bot for discord and i want it to show a random image when i type g!guess. so i made it work with
if (message.content === 'g!guess') {
number = 2;
imageNumber = Math.floor (Math.random() * (number - 1 + 1)) + 1;
message.channel.send ( {files: ["./images/" + imageNumber + ".png"]} )
}
it shows a random image, i actually have only 2 images named 1.png and 2.png.
I'd like to make that when a random image is shows if i type its name i get a message, like i have 2 images a space image and a dog, if the dog image appear and i write 'dog' i get a message, and if i type something else nothing happen, if i write g!guess and the space image appear, if i write 'space' i get the message. I'd like it to show an image and that i have like 20 second to guess the name of it, and when the time finish it show a message like 'Time's out'. I hope its understandable.
If I understand you correctly, you're trying to inform the code that 1.png is a dog image whereas 2.png is a space image. It would be easier to guide you with a copy of the code but here's a high-level walkthrough:
I would go about this by adding an alt tag to each image and reference it in the javascript function.
for example:
<img src="src/to/img.png" alt="dog"/>
Here's how to reference the alt tag using javascript: Finding An image tag using the alt text
hth.
I have asked the question on the repository directly, but in my experience SO is more reactive.
Hey there,
I am trying to create a pdf from photos using pdfkit.
Depending on whether an image is in landscape or portait mode, I want to turn the image around.
This basically means the following (in typescript) :
function toPostscriptPoint(mm: number) {
return mm * 2.8346456693;
}
const document = new PDFDocument({
size: [toPostscriptPoint(156), toPostscriptPoint(106)],
});
document.pipe(fs.createWriteStream('output.pdf'));
document.save();
document.rotate(90);
document.image(
'photos/sample.jpeg',
{ width: toPostscriptPoint(150), fit: [toPostscriptPoint(150), toPostscriptPoint(100)] });
document.restore();
document.end();
What happens though is that the pdf renders completely white. I do see however that something is happening, because the pdf has the size of the input image.
Is rotation for images not supported? What would be possible alternatives? I would like to avoid having to rewrite my files before putting them in the pdf.
Thanks
Alright, after investigation, I can answer my own question :).
I could see that the images were in the pdf somehow because of the size of the file so I dived deeper.
What happened was that the image was rendered out of the viewport. This was due to multiple things:
By default, the origin of a page after rotation in pdfkit is the center of the page! ( See the doc for more info)
The origin is rotated together with the transformation.
The x and y in the image method are actually inverted.
So after getting all this right, the following code shows the image as expected :
function toPostscriptPoint(mm: number) {
return mm * 2.8346456693;
}
const document = new PDFDocument({
size: [toPostscriptPoint(156), toPostscriptPoint(106)],
});
document.pipe(fs.createWriteStream('output.pdf'));
document.save();
document.rotate(90, {origin : [0, 0]});
document.image(
'photos/sample.jpeg',
toPostscriptPoint(0),
toPostscriptPoint(-150),
{ width: toPostscriptPoint(150), height: toPostscriptPoint(100) });
document.restore();
document.end();
Note the :
origin argument in the rotation
toPostscriptPoint(-150) actually takes into account the position of the origin, and corresponds to the X axis.
Hope that helps some later on :).
Its because taking picture from camera , if picture ISO is less than 100 it will be automatically rotated , take picture with iso more than or equal to 100 to avoid autorotation.
I've been looking for a solution to this but I cannot seem to find one for linking an edge label to another GraphViz Dot Graph. For example, if I have a graph called 'mydotimage2.svg' produced from the following:
digraph G
{
graph [compound = true];
subgraph cluster_0
{
node [style = bold];
"A" "B" "C";
}
subgraph cluster_1
{
node [style = bold];
"One" "Two" "Three";
}
"A" -> "One" [lhead = cluster_1, ltail = cluster_0, label = "Falafel", href = "~/workspace/GraphViz/mydotimage1.svg"]
}
If I create the 'mydotimage2.svg' SVG image in my terminal via:
dot -T svg mydotimage2.dot > mydotimage2.svg
The image opens just fine in my browser, and the edge label from A to One in the produced image is clickable, but does not open mydotimage1.svg which is in the same GraphViz directory as well. Does anyone know how to do this? I would really appreciate it. Thanks in advance.
You should use relative paths.
That is, instead of href = "~/workspace/GraphViz/mydotimage1.svg" use href = "./mydotimage1.svg"
BTW, instead of using pipe redirection(>) you can specify desired output file name as a parameter to the dot.
Just append -omydotimage2.svg to the command line.
Where "mydotimage2.svg" is the file name you want to write to.
This is what I observe on my machine, I guess it's a general problem:
graphviz does expand the tilde ~ to but it does not remove the tilde. In my case I see /home/rainer/~/workspace/GraphViz/mydotimage1.svg as image location when I click on the hyperlink in the graph. That obviously doesn't exist. Looks like a bug to me...
The solution / workaround is to replace the ~ in the script with your home folder path, in my case
href = "/home/rainer/workspace/GraphViz/mydotimage1.svg"
which works as expected.
I am trying to put in an icon (a scaled image) as part of a button that also contains some text. I am programming in J2ME for the Nokia SDK (S60 device) and using Eclipse.
The code is as follows:
but = new Button("Some text");
Image img = null;
try {
img = Image.createImage("/flower.png");
} catch(IOException e) {
e1.printStackTrace();
}
but.setIcon(img);
The above lines are the code that works properly. I am facing problems in scaling the image to the size of the button. Whenever I try to do that, I get a divide by zero error. The function I am using to scale the image and the way it is being scaled is:
Image img2 = null;
img2 = img.scaled(but.getWidth()/2, but.getHeight());
but.setIcon(img2);
I am unable to figure out why I get a divide by zero error every time I try to run the above code. Is there some other function that I should use? Or is there something I am missing ?
which UI Framework are using, is it LWUIT? if yes, you can't get the width/height of any component before showing the form, you should use getPreferredWidth instead