I'm trying to reset the Orientation EXIF field in my image using rmagick 2.13.1 and ruby 1.9.3p194, but it doesn't seem to save.
img = ::Magick::Image::read(local_source_path).first
img.get_exif_by_entry()
=> [["ColorSpace", "1"],
["ExifImageLength", "2448"],
["ExifImageWidth", "3264"],
["ExifOffset", "38"],
["Orientation", "6"]]
Orientation can also be acquired thru the properties
img.properties
outputs
{"date:create"=>"2014-01-08T17:26:10-08:00",
"date:modify"=>"2014-01-08T17:26:05-08:00",
"exif:ColorSpace"=>"1",
"exif:ExifImageLength"=>"2448",
"exif:ExifImageWidth"=>"3264",
"exif:ExifOffset"=>"38",
"exif:Orientation"=>"6",
"jpeg:colorspace"=>"2",
"jpeg:sampling-factor"=>"2x2,1x1,1x1"}
I try to set Orientation property to nil & save:
img['exif:Orientation'] = nil
Now,
img.properties
=> {"date:create"=>"2014-01-08T17:26:10-08:00",
"date:modify"=>"2014-01-08T17:26:05-08:00",
"exif:ColorSpace"=>"1",
"exif:ExifImageLength"=>"2448",
"exif:ExifImageWidth"=>"3264",
"exif:ExifOffset"=>"38",
"jpeg:colorspace"=>"2",
"jpeg:sampling-factor"=>"2x2,1x1,1x1"}
which looks correct.
img.write(local_dest_path)
but when I use get_exif_by_entry
img.get_exif_by_entry('Orientation')[0][1]
I still get 6 & not nil.
When I read the written file that was modified local_dest_path, I still get "6".
Is there a set_exif_by_entry function that I'm missing? Any ideas? Thanks
Couldn't set to nil, but I was able to set it to 1 during the write
img.write('local_dest_path') { self.orientation = ::Magick::TopLeftOrientation }
The constant UndefinedOrientation didn't work either. Other values available are listed in OrientationType.
Related
I have a cookies.permanent[:liked]:
cookies.permanent[:liked] = 'liked1#liked2#'
I removed liked1#:
cookies.permanent[:liked].slice! `liked1#`
I get cookies.permanent[:liked]:
'liked2#'
Next, I removed 'liked2#':
cookies.permanent[:liked].slice! `liked2#`
and I thought I would get '', but I got:
'liked1#'
And I printed cookies.permanent[:liked], I got 'liked1#liked2#'!
I just want to delete a substring of cookies value, but I find it still can be read.
So, how to do that? Note, I must use permanent.
Yeah, I find I can do this by this:
temp = cookies.permanent[:liked]
wanted_deleted = 'liked1#'
temp.slice! wanted_deleted
cookies.permanent[:liked] = temp
Now, value of cookies.permanent[:liked] is 'liked2#'
There has more efficient ways?
I want to programmatically fill a pdf using pdf-form gem
I was able to read the fields using the following code:
require 'pdf_forms'
pdftk = PdfForms.new('/usr/local/bin/pdftk')
fields = pdftk.get_fields('*/Desktop/sample_pdf.pdf')
for f in fields
print f.to_s
end
But when I tried to fill the Pdf with the provide synthax, I created only an empty, not openable pdf.
pdftk.fill_form '/path/to/form.pdf', 'target.pdf', ['Value Name'] => 'Value to be inserted'
Does anybody know a working solution?
Thanks in advance!!!
Additional Information:
the fields of the pdf are the following: Name, Address, Dropdown1, Dropdown2, Dropdown3, Check Box4, Check Box1, Check Box3, Check Box2, Text5, Button7, Text6, Group6, %
I tried it with filling just one field:
pdftk.fill_form 'sample_pdf.pdf', 'sample_pdf_filled.pdf', {["Name"]=>"Value to be inserted"}
The result: I have an pdf "sample_pdf_filled.pdf", which I cannot open, because it's empty. I thought my problem is the form-filling, but it seems, that the pdf is not created correctly.
Note: I am working on a mac (unix)
Has anybody a solution?
Method #fill_form is defined like this:
def fill_form(template, destination, data = {}, fill_options = {})
You example would produce something like this:
irb(main):001:0> { ['Value Name'] => 'Value to be inserted' }
=> {["Value Name"]=>"Value to be inserted"}
The data is supposed to be a Hash. If you want to specify a key with a space you can use it like this: :'Value Name'.
irb(main):002:0> { :'Value Name' => 'Value to be inserted' }
=> {:"Value Name"=>"Value to be inserted"}
I found a solution - for all MAC OS X 10.11 El Capitan User:
PDFtk Server on OS X 10.11
I try to make that, in the controller ...
raw_counter_reset_date = REDIS.hget(params[:id], 'overquota_reset_at')
#counter_reset_date = Time.at(raw_counter_reset_date)
But when I want lauch application, I have this error :
can't convert nil into an exact number
I know that #counter_reset_date = Time.at(1364046539) works with numbers, but I would that the application take the timestamp date in a database and convert in date on my web-page.
I hope to have been understandable, and thank you in advance for your help.
this is because raw_counter_reset_date is nil. convert it to a number (raw_counter_reset_date.to_i) or check for nil.
i have two volumes (.nrrd) of different qualities. the user can browse through the layers. if a key is pressed
i want to load the slice of the volume with better quality.
my volume is similar to this one: lesson 10 xtk
i've found:
volume.children[2].children[0].children[0].texture.file = "http://path/to/file.ext";
but if i apply some kind of file (.jpg, .dcm) nothing happens.
is this the right approach to change the slice to go inside the children and change the texture?
or shall i load the selected slice seperate as an object and apply it to the "lower-quality-volume" somehow?
edit:
this is what i tried so far (i get errors with dcms but not with jpgs):
if (event.keyCode == 83) { // "s"-button
volume.children[2].children[0].children[0].texture.file = "http://localhost:3000/112.jpg";
volume.children[2].children[0].children[0].modified();
r.render();
}
edit2: this is whats in my r.onShowtime = function() {}
volume.children[2].children[0].texture.file = 'http://localhost:3000/112.jpg';
volume.children[2].children[0].visible = true; // to activate the first layer
volume.children[2].children[0].modified();
console.log(volume.children[2].children[0].visible +" "+ volume.children[2].children[0].texture.file);
it outputs "true hostname/112.jpg"
when i inspect the .jpg in firebug the header is ok but the answer is "null"
when i inspect console.log(volume.children[2].children[0]); with firebug
.texture.file is set to hostname/112.jpg
when i go to "network" the .jpg has been transfered successfully
please notice that 112.jpg and level.jpg are the same. the first one is getting loaded in r.onShowtime and the other one is loaded at a keypressed event.
EDIT 3: volume.children[2].children[0] is of the type "X.slice", isn't it?
here is my approach: jsFiddle
and this is my actual issue and still not working: jsFiddle
Mhh..
I think a call to object.modified() is missing in the file setter (and in others setters from inject classes). Let's see when Haehn will come if he wants to change something internaly, but for the moment could you try to call it by yourself ?
You can try to add after the modification of texture :
volume.children[2].children[0].children[0].modified();
And if it doesn't work, in addition :
renderer.render();
Edit :
It's strange, I did a similar code and it did something. Can you please try something like that with opening your javascript console (Firefox, Chrome,... has one) and tell me the error you get ?
renderer.onShowtime = {
for (var i=0 ; i< volume.children[2].children.length ; i++) {
volume.children[2].children[i].texture.file="myimage.jpeg";
volume.children[2].children[i].modified();
}
}
It is important you call it in the onShowtime, because before the volume is not loaded, and so slicesX, slicesY... don't exist.
Edit2 :
Hey,
Thanks to the informations you added I think I've got the point ! In the render() method of our renderer3D there is a test on texture._dirty flag, that you cannot change from outside the framework. In addition the 1st rendering with a texture make that flag false, and loading a new texture doesn't seem to set that flag back to true in the current XTK. So, I think, we have to add it in the loader.load(texture, object) method. I'll make an issue on Github and see what Haehn thinks of it !
I'm trying to create an instance of my CompanyLogo model if the hash params[:vacancy]['companies']['company_logo'] is pressent. I'm attempting to do this:
l = CompanyLogo.new( :company_logo => params[:vacancy]['companies']['company_logo'].tempfile.path )
but that gives me
CompanyLogo(#70304040244500) expected, got ActionDispatch::Http::UploadedFile(#70304015073440)
Is there a way to do this?
If your CompanyLogo has_attached :logo,and you are saving file manually then simply company_logo_object.logo = File.new(actual_path) and
company_logo_object.save solve your purpose
Try saving the logo first (tested in Rails 3.2.2 using Paperclip)
(logo = CompanyLogo.new(:image => params[:image])).save
company_object.update_attributes(logo: logo)