I am working in R Markdown to create a PDF Output and trying to fit my outputs to a single page. I'm a bit over at the moment, and want to remove the extra white space around an image.
knitr::include_graphics(("File_Name.jpeg"))
I have tried par(mar(c(0,0,0,0)) which seemed promising based on the description here but that seems to scale the image.
I also tried using out.width but that didn't seem to impact the image at all.
Two steps resolved this for me.
First, I added the code below to the ggplot code which was creating the original graph image in a separate r script file, that I was saving and later inserting into the rmd file.
plot +
theme(plot.margin = margin(0, 0, 0, 0, "cm"))
This helped to reduce the margins but there was still an extra space at the bottom which appeared in PDF Output files between blocks.
So, Second, following the guidance in https://stackoverflow.com/questions/59640925/rmarkdown-how-to-reduce-space-between-title-block-and-start-of-body-text
I added the code below after inserting the image (right before the first set of text) to reduce the extra spacing Markdown adds between blocks.
\vspace{-5truemm}
Related
Im 15 and a newbie trying to learn more about image storage. I wrote a script in python to create a bitmap image without any imports. Im familiar with PIL/PILLOW, im not using any imports simply to learn more, as they will not help explain images at a binary level. my issue is that when i try to draw to the image, it gets distorted. For example, the code I've attached should draw out straight rows of black and white lines, but on the image it generates (attached as a png as SO won't attach a .bmp), there are fault lines where the image goes askew.
#The header contains all the metadata of the file, so that it can be scanned and displayed correctly.
#I've attached details of this header to my question
header=[b'\x42',b'\x4d',b'\x18',b'\x31',b'\x0c',b'\x00',b'\x00',b'\x00',b'\x00',b'\x00',b'\x36',b'\x00',b'\x00',b'\x00',b'\x28',b'\x00',b'\x00',b'\x00',b'\x80',b'\x02',b'\x00',b'\x00',b'\xaa',b'\x01',b'\x00',b'\x00',b'\x01',b'\x00',b'\x18',b'\x00',b'\x00',b'\x00',b'\x00',b'\x00',b'\x00',b'\x00',b'\x00',b'\x00',b'\x00',b'\x00',b'\x00',b'\x00',b'\x00',b'\x00',b'\x00',b'\x00',b'\x00',b'\x00',b'\x00',b'\x00',b'\x00',b'\x00',b'\x00',b'\x00']
#create a file to write the image to, in biinary.
#you may wish to change the file path
with open ("test.bmp","wb") as f:
#first write in the header
for i in range(len(header)):
f.write(header[i])
#now write in the pixel data
#640 is the image width
for x in range(0,640):
#426 is the image height
for y in range(0,426):
#if the row is an even number, make it a white pixel.
if x %2 ==0:
byte_arr=[255,255,255]
#else make it a black pixel.
else:
byte_arr=[0,0,0]
#write the pixel data bytes to the file
some_bytes = bytearray(byte_arr)
immutable_bytes = bytes(some_bytes)
f.write(immutable_bytes)
this article has been very helpful in clearly explaining the bitmap format.
[])
I have been able to change the number of fault lines by changing the number of rows, but i cannot get rid of them entirely. I suspect the problem is in the files meta-data, but ive checked through it and cannot find any bad data. I've attached a (slightly messy) breakdown of the header ive used, which the article also explains in more detail.
I have multiple images in the column portion of a matrix that displays the image if there is one. If there is not an image defined for the image number, the report correctly hides the image (as the BorderColor = Black is not shown) but the white space still remains.
I have tried every possible combination (except the correct one obviously) to no avail.
My objective is to only have the width of the 8 images be 2
Any Ideas?...And splitting the images into individual lines is not an option as it negates the whole premise of using the Matrix.
I have tried placing the hidden code in every possible Hidden field in the report. All postings found all refer to a SINGLE image and not MULTIPLE images.
I have two things I have been using, neither of which are keeping the image/table exactly where I placed it within the text in R markdown when knitted to a pdf.
![caption](path) will place the image where there is space on the page. That is, if the page has space, the image will print between the desired text. However, if the page does not have the space, the text is placed to fill the page and then the image awkwardly inserts itself in the middle of the paragraph on the next page.
I am having a similar problem with my kable tables. I have tried using latex_options = 'hold_position', but this seems to only keep my tables from grouping together.
Is there a way to have my table stay between the text that I want? So if it needs to start a whole new page, to fit it, it can without trying to fill the space with the text below.
Thank you in advance.
I'm using the print function in MATLAB to write images of plots, something like that
print(figure(1),'-dpng','-r300',filename);
But apparently the images are not overwritten, and the original images stay. I was using saveas before, which seems to overwrite the images, but print gives me more output options. Any ideas?
UPDATE: I ended up deleting the files before the printing with a different function.
You can use this:
im = frame2im(getframe(gcf,rec)); %Grabs image of plot as an image
imsave(im, filename); %save image
That syntax may not be 100%, its a while since I've used it.
Also be aware that this isn't perfect - I remember having issues with it grabbing a grey border around the edge of the plot. Also, I think the image may be based on a matlab screenshot.... just something to be aware of
Saving figures in matlab is rather troublesome, especially if the saved image should look like the original figure.
For myself i found the solution in using export_fig.
It's one of the most downloaded fileexchange files - maybe you should give it a try:
http://www.mathworks.de/matlabcentral/fileexchange/23629-export-fig
A small introduction to export_fig can be found at:
https://github.com/ojwoodford/export_fig/blob/master/README.md
I'm currently looking for a way to create a 'configurator' for a upholsters, similar to http://digitaldraping.com/configurator/furniture-sofa/?Cushions_Plain-Cream.png,Sofa_Stripe-Orange.png - you select your fabrics and they are 'drawn' on the sofa automatically.
Unfortunately, all the sites I've looked at seem to use pre-rendered transparent PNGs that are overlaid over each other to build up the full picture. The problem here is that we've figured out that we'd require over 120,000 different images to cover all models, fabrics etc!!
I've looked at a few 3d texture tools such as http://www.arahne.si/products/arah-drape.html, hoping that one of them would have a CLI option where you give it a pre-created wireframe, and a fabric to overlay, and it generates the required image on the fly, but so far everything seems to require real-time use of the GUI to use it.
So, is there a CLI tool that would do what I'm after, or can anyone suggest a way to manipulate the GUI automatically? (from a tech point of view, I'm comfortable with C, Bash, Python or PHP as a solution!)
Thanks!
ArahDrape 2.2 can now work from a command line without any GUI interface. You can also call ArahDrape as a C library. In this way, it can be used in a web server to create texture mapped images on the fly. The command line options are explained below.
ArahDrape 2.2j command line version, ©2015 Arahne
usage:
adCommand -o /tmp/outputImage.png -tN /home/user/texture.png [-hidemodel] [-divide 2] [-filterPNG] [-compressPNG 2] [-m /home/user/model.png] -owner name -activation 174b3cfb49e9 /home/user/project.drape
Input and output images can have png, .tif or .jpg extensions
-o output_image_file
-tN texture_image_file [N goes from 0 to 199]
-hidemodel will render all areas not in region as white
-divide N [N goes from 2 to 5] divide resulting image pixel size
-filterPNG if you do not filter it, rendering is faster
-compressPNG N [N goes from 0 to 9] lower number saves faster, but bigger files
-m model_image_file use this if you want to replace model image from the project; must have same pixel size
-owner owner_name pass the given owner name
-activation activation_code pass the given activation code
last parameter should be ArahDrape project file
All files should be entered with full path.
If you need spaces in filenames, use quotes "" around the filename.
If you provide only Owner name, without activation code, program returns registration code.
ArahDrape supports batch export.
Open ArahDrape project, click on texture you wish to replace, put all your texture in a directory, select from menu
Textures > Browse textures, and as you click the texture to load it, program will save the draped picture. If you have thousands of images, use keyboard shortcut = and program will automatically do them all.
Alpha channel transparency is supported in loading model images or textures, and saving the draped images, as long as you use PNG or TIFF.
Please check this video to see how
ArahDrape works in batch mode.
we (http://digitaldraping.com/) can do just what you are asking. We have two options creating images and rendering a meshed image on the fly. Just get in touch if you still need this solution.