Why does Responsive FileManager resize images after upload? - upload

I am using Responsive FileManager to upload images to my site. However, there is a problem that whenever I upload an image its immediately resized and cropped to a smaller size. Does anyone know why is this happening and is there a way to stop it.
Thanks.

You may check the config.php file and set $image_resizing to false:
//Automatic resizing //
// If you set $image_resizing to TRUE the script converts all uploaded images exactly to image_resizing_width x image_resizing_height dimension
// If you set width or height to 0 the script automatically calculates the other dimension
// Is possible that if you upload very big images the script not work to overcome this increase the php configuration of memory and time limit
'image_resizing' => false,
'image_resizing_width' => 0,
'image_resizing_height' => 0,
'image_resizing_mode' => 'auto', // same as $image_max_mode
'image_resizing_override' => false,
// If set to TRUE then you can specify bigger images than $image_max_width & height otherwise if image_resizing is
// bigger than $image_max_width or height then it will be converted to those values

Related

google docs api - insert inline image not resizing image to specified size

so I have been making some image requests with the google docs api using javascript, but I have been unable to change the image size when I make the request.
All the images seem to be appearing in their original size in the google doc.
So I am wondering what I am doing wrong. The documentation seems to be pretty clear:
https://developers.google.com/docs/api/reference/rest/v1/documents/request#InsertInlineImageRequest
Basically it just says to specify objectSize width and height, using magnitude and units (PT).
Here is the function I use to append to my full request, where I specify all of these.
function imageRequest (url: string, width: number, height: number) {
const request:Array<object> = [ {
insertInlineImage: {
uri: url.toString(),
objectSize: {
height: {
magnitude: height,
unit: 'PT'
},
width: {
magnitude: width,
unit: 'PT'
}
},
location: {
index: 1
}
},
} ];
return request;
}
And then I'm pushing each image request to the full request like.
request.push(imageRequest(image.image.url, 468, 648));
but whatever I put for the width and height is not doing anything. The images are always the original size.
The images are public on an s3 style hosting at Wasabi (similar to amazon s3)
I cannot think of what the problem could be, maybe it's something small that I am overlooking?
help is appreciated, thanks.
The image dimensions are defined by the objectSize property and the Docs documentation states a few rules that define the final size of the image:
If neither width nor height is specified, then a default size of the image is calculated based on its resolution.
If one dimension is specified then the other dimension is calculated to preserve the aspect ratio of the image.
If both width and height are specified, the image is scaled to fit within the provided dimensions while maintaining its aspect ratio.
From these rules it seems that Docs will prioritize the aspect ratio of an image over the exact size, so even if you specify a certain set of dimensions, Docs may resize it to preserve the ratio. As a workaround you can specify only the dimension that you deem more important, (width or height) and Docs will calculate the other one automatically.
In addition, it seems that Docs uses points (PT) rather than pixels (PX) as units to measure dimensions. One point is 1/72 inch while one pixel is 1/96 inch, so if you're used to calculating sizes in pixels as it's most common you'll need to make this conversion as well. A pixel will be 0.75pt while a point will be 1.333...px.

How to get the width and height of an image by Url in Google Sheets

I have in a Google Sheet a list of images by URL. Images are on a remote server.
I got the preview in my Sheet by the Image (URL) function.
Is there a way to get the width and height of each remote image in each row by formula or script?
Looking through the Google Community docs, found this question asked here with no apparent solution.
It's not exactly what you're looking for, but you could use the IMAGE function to set the dimensions your images.
IMAGE(url, [mode], [height], [width])
url - The URL of the image, including protocol (e.g. http://).
The value for url must either be enclosed in quotation marks or be a
reference to a cell containing the appropriate text. mode - [ OPTIONAL
- 1 by default ] - The sizing mode for the image
1 resizes the image to fit inside the cell, maintaining aspect ratio.
2 stretches or compresses the image to fit inside the cell, ignoring
aspect ratio.
3 leaves the image at original size, which may cause cropping.
4 allows the specification of a custom size.
Note that no mode causes the cell to be resized to fit the image.
height - [ OPTIONAL ] - The height of the image in pixels. mode must
be set to 4 in order to set a custom height.
width - [ OPTIONAL ] - The width of the image in pixels. mode must be
set to 4 in order to set a custom width.

RMagick - how to create a thumbnail with an automatic height?

I am using RMagick for creating thumbnails like this:
img = Magick::Image.read(image_url).first
target = Magick::Image.new(110, 110) do
self.background_color = 'white'
end
img.resize_to_fit!(110, 110)
target.composite(img, Magick::CenterGravity, Magick::CopyCompositeOp).write(thumb_path)
This works well - I'll load the current image, create a "space" for the new thumb and then will place it there.
However, I would need to create a thumb where would be the width 110px and the height would be automatically counted... How to do this?
Thank you
You'd rather use resize_to_fill!
Doc here
image = Magick::Image.read(image_url).first
image.format = "JPG"
image.change_geometry!("110X110") { |cols, rows| image.thumbnail! cols, rows }
image.write("<path to save thumbnail>")
This turns out to be super easy! ImageMagick and GraphicsMagick both maintain aspect ratios properly, so in your case, just give the max width you want the image to be. See http://www.imagemagick.org/script/command-line-processing.php#geometry to learn more about the magick dimension operators.
If you find that you're ruby process' RAM consumption is growing, you may want to switch to an external-exec image library, like https://github.com/mceachen/micro_magick. Also, switching to GraphicsMagick is an all-around win, BTW, giving better image encoding and in less time.
require 'micro_magick'
img = MicroMagick::Convert.new("input.png")
img.resize("110") # this restricts to width, if you want to restrict to height, use "x345"
img.unsharp(1.5) # This runs an "unsharp mask" convolution filter, and is optional
img.write("output.png")

How do you get Highcharts to scale up image contents rather than add more details?

I am trying to generate PDF documents server side containing data tables and charts generated by HighCharts. I am using highchart-serverside-export and iText.
I have been able to generate the documents but the chart images are grainy when printed. From what I understand, iText uses 72dpi by default when inserting an image. The correct way to get higher fidelity images is to start with a larger image and scale it down using one of the scaling functions such as scalePercent().
I can easily generate a larger chart image by passing in larger height and width parameters to Highcharts. The problem is that when you increase the dimensions of the chart, the content does not scale up (eg. font size of lables). In fact, you get more detail in some places (eg. more axis ticks). The reason this is a problem is that when you then apply the scaling down via iText, these items become very small and hard to read.
I have looked at the Highcharts API and cannot see a way to get Highcharts to scale up the contents rather than add more detail. How do I get this to work?
If the approach I am using is completely wrong, the wider question is how do I get print resolution server-side Highcharts charts? I have to use iText but am willing to try an alternative technology to do the chart rendering.
try this
exporting: {
sourceWidth: 1000,
sourceHeight: 400,
},
Link to JsFiddle
You can specify the width of the exported image using the exporting.width property.
This will not increase the size of the div or add/remove details or anything of that sort, it will simply scale the generated svg according to the specified width, maintaining the aspect ratio. Hence also scaling everything including texts etc.
exporting: {
width:2000 // or scale down to 100
}
Upscaling exported images / pdf | Highcharts & Highstock # jsFiddle

Prawn : adding background image of larger resolution

I'm creating a pdf book where I need to put a background image for each page.
The size of the page is (576 x 576) and the size of the background image is 2700 x 2700 (300 dpi.) (These sizes are the requirements so cannot be adjusted).
My problem is - the background image appears out of proportion in the page. How can I fix this ?
Here's my code:
Prawn::Document.generate("#{Rails.root.to_s}/public/#{filename}.pdf", :page_size => [576,576], :left_margin => 50,
:right_margin => 50, :page_layout => :portrait, :skip_page_creation => true, :skip_encoding => true,
:background => "#{Rails.root.to_s}/public/images/pdf/bg_blank_low.jpg" ) do |pdf|
....
....
....
)
Is there any other way by which I can place the image of 300 dpi as a background image.
I even tried adding pdf template as a background, but still no luck.
Any suggestion or hint will be much appreciated.
Thanks.
What you're trying to do can't be done using the :background option of Prawn::Document.generate since the :background option can't scale the image. If you want to use the :background option, you need to make sure your image is the same dpi as the PDF (normally 72dpi).
You can however simply imbed the image in the page, like you would a normal image and then float the text over the top of it. This works since when you embed an image you're able to scale it. The code might look something like this:
Prawn::Document.generate("#{Rails.root.to_s}/public/#{filename}.pdf", :page_size => [576,576], :left_margin => 50, :right_margin => 50, :page_layout => :portrait, :skip_page_creation => true, :skip_encoding => true) do |pdf|
bg_image = "#{Rails.root.to_s}/public/images/pdf/bg_blank_low.jpg"
pdf.image bg_image, :scale => 0.2311
pdf.move_up 576
end
This will make your 'background' fully cover the page (since we manually calculated the scale 2700/576), if you want to respect your margins (this is probably a better way in general), you might alter to something like:
pdf.image bg_image, :width => pdf.bounds.width
This should automatically scale the image based on the width of the bounding box of the page. Of course you would need to change your move_up as well, something like:
pdf.move_up pdf.bounds.height
After you did this you can start putting your text in and it should appear over the top of your image and so we get our simulated scaled background.
Update
This is an update with regards to the comment. If you have pages being automatically created and you want them to have the same background then you're out of luck if you're using the current prawn release the way it is. If you really need this functionality, then you have to patch prawn.
Grab the prawn source (from https://github.com/sandal/prawn) and have a look at it. What you're after is lib/document.rb, on line 244 there is a method start_new_page, this is the one you're after. Within this method on line 280, you can see where the background is being set. Unfortunately it is using canvas which means, your image already has to be of the right size. This is why the background image doesn't scale automatically.
You will need to override this behaviour. Since this is Ruby, all you have to do is reopen the class within your project and then copy paste this method in (if you need more info on how to do this, there is plenty around on monkey-patching Ruby classes). Now you edit this method to your hearts content. The easiest way is probably to remove the canvas all together and then use our image trick from above. So the line ends up as:
image(#background, :width => bounds.width) if #background
move_up bounds.height
You can now go back to using the standard way of setting the background and everything should work.
Infact, you may even be able to get away with changing line 280 to this:
canvas { image(#background, :width => bounds.width) } if #background
And everything should work fine, saving you having to type an extra line :). Using image with the :width option should automatically scale the image, while using the :at option as prawn does won't scale the image.
Note: I haven't actually done this so you may need to work the kinks out.
If you only have one PDF page, a solution is to just don't use the background property at all, but just place the image at the first position of each page and define width as the full width with
pdf.bounds.width
If someone needs to add the picture after pages have been generated or just adding a transparent picture you can use :
pdf.transparent(0.5) do
pdf.image(file, options = {
:at => [200, 220],
:scale => 0.2
})
end

Resources