I am using Ruby and MiniMagick to do some image manipulation.
I've added a drop shadow to a png, and I'm trying to crop off a side so that I can line it up with another image without the shadow overlapping with it in a very odd looking manner.
I've tried to use chop. This works perfectly, except it will only chop off the left edge instead of the right. I've tried changing the gravity, but this is fully ignored.
page1.gravity 'East'
page1.chop '8x0'
The code above chops 8 pixels off the left, even though everything I've found indicates it should be chopping 8 off the right.
I've tried to use crop. Using just crop with a layered image returns no image at all.
I've tried to use crop and repage:
page1.crop '200x500+0+0'
page1.repage.+
This returns the following error:
/Users/elizabethday/.rbenv-usergems/2.0.0-p247/gems/mini_magick-3.6.0/lib/mini_magick.rb:409:in `run': Command ("mogrify -repage /var/folders/HH/HHJiNl08GyWfBCFvHn2R9++++TU/-Tmp-/jpg20131009-14809-1tjeck0") failed: {:status_code=>1, :output=>"mogrify: invalid argument for option `/var/folders/HH/HHJiNl08GyWfBCFvHn2R9++++TU/-Tmp-/jpg20131009-14809-1tjeck0': -repage # error/mogrify.c/MogrifyImageCommand/5558.\n"} (MiniMagick::Error)
from /Users/elizabethday/.rbenv-usergems/2.0.0-p247/gems/mini_magick-3.6.0/lib/mini_magick.rb:363:in `combine_options'
from /Users/elizabethday/.rbenv-usergems/2.0.0-p247/gems/mini_magick-3.6.0/lib/mini_magick.rb:342:in `method_missing'
from menu_thumbnails.rb:114:in `<main>'
This error indicates that it's using the -repage option, when I specifically told it to use +repage.
I've tried flattening the png, but this just ends up as a black box.
Does anyone have any suggestions on how to get this to work?
EDIT: Ok, I've discovered that, in general, gravity needs to be used in a combine_options block.
However, when using a combine_options block it still doesn't work properly.
The following block:
page1.combine_options do |c|
c.gravity 'East'
c.chop '8x0'
end
does absolutely no chopping of the image at all. So I still seem to have made no progress in getting this image properly cropped.
Put repage.+ inside of your combine_options block as well. I've been having loads of the same type of issues you're having.
page1.combine_options do |c|
c.repage.+
c.gravity 'East'
c.chop '8x0'
end
Related
I'm working with fastai, trying to pass some images to a dataloader. The original images are kind of pinkish, but after passing them they appear mostly as green-black (see image in link below):
Original pinkish image (up) and example images (down) after passing them to dataloader, and the code.
The code I've used for the datablock and to show the images is:
example = DataBlock(
blocks=(ImageBlock, CategoryBlock),
get_items=get_image_files,
splitter=GrandparentSplitter(),
get_y=parent_label,
item_tfms=Resize(128)) #already tried it without item_tfms just in case, still black-green
dls = example.dataloaders(path)
dls.show_batch(nrows=1, ncols=3)
I tried with .tif and .jpeg images, and both show the same problem. The only thing that comes to my mind is that somewhat somewhere is not reading correctly the color format (RGB according to my original files), or maybe transforming it; but I'm not able to figure it out.
Just in case it's important, I'm working in a Jupyter notebook with a MackBook Air M1.
Thanks!
Irene
So I have a programming project that I have to do for my school. What I have to do is setup a 2 player dice game. I could have gone the easy way and just display the number of the 2 die, but I was thinking of using images that I made in photoshop instead. However, the problem is that I do not know how to change images in an efficient way.
My first option is using the visibility tag on several images laid on top of eachother and change it accordingly as such
image1.visible = false
image2.visible = true
However, I do not think that is very efficient. Images also do not support changing the image with code from my research.
Secondly, I could use a PictureBox instead, which do support changing the image as the program is running. However, it does not support transparency, and the die images are transparent. Plus it gives me the invalid image file error, I guess due to the transparency in the gif files.
There is also the cheap workaround of me making the background of the images the same as the form background.
So is there a more efficient way I am missing out? I know that the cheap workaround would be the best option for this case, but I would like to have this knowledge for future use like semi-transparent pixels that blend in and such.
And before you ask, no, I cannot use another programming language as visual basic 6 is what my school teaches. Thankfully they are changing it soon, but I am stuck with this for now.
Turns out you CAN change the pictures of Images, while keeping transparency and stretch. I am going to properly show it:
Image1.Picture = LoadPicture("YOURPATHHERE.gif")
This is what I get for believing what I've seen on some forum.
Also, the error of invalid image file was due to the images being corrupted for some reason.
The servers where I work upgraded some libraries and now I am getting a weird behaviour out of ImageMagick version 6.7.8-9.
I am using the command
composite -compose Multiply bkg.gif overlay.gif output.gif
which used to put overlay.gif, which is a mostly white image, on top of bkg.gif. Now the same thing is happening but bkg.gif is negated! I have tried to change from Multiplyto Screen, which, according to the docs is the same thing but negates both images and back, but the output was the same.
I have worked around this by negating image bkg.gif before doing the same operation but this is not correct and I still have to do this is many scripts that use the same command, so I would like to effectively solve the problem or at least understand it.
Why is this happening? I apologize but I cannot provide the images we are using.
I've tried finding the answer to this all over the place, but I've had no luck so far. You see, I've ran into a problem where I'm generating gif files by appending images into a single gif using a for loop. But after a while, imwrite seems to stop actually adding the images into the gif file - it just adds white spaces instead.
So, the file itself is large enough (250MB) to feasibly have the right number of images in, but when I open it and play it, once it gets past a certain point I just have white images. I'm pretty damn sure it's nothing to do with the for loop itself - I've had it print out the image file it's working on for each loop iteration and that's correct. The filenames are all correct.
It just seems to give up after a certain number of images, so my thought is that maybe there's a maximum number? I have over 50 frames that I want to stitch together.
The code snippet I'm working on:
delay_time = 0;
% for each frequency, read in the iso-contour and stitch to the plots
% together to make a gif
for counter_frequency = freq_min:freq_inc:freq_max
im_in = imread(['2D FFT, ' num2str(counter_frequency, '%3.2f') ' GHz.png'], 'png');
[imind,cm] = rgb2ind(im_in,256);
disp([num2str(counter_frequency)]);
if counter_frequency == freq_min
imwrite(imind,cm,[directory.plot.iso_plots '\Iso-frequency Animation.gif'],'gif','DelayTime',delay_time,'LoopCount',inf);
else
imwrite(imind,cm,[directory.plot.iso_plots '\Iso-frequency Animation.gif'],'gif','DelayTime',delay_time,'WriteMode','append');
end;
end;
Solved it! There was nothing wrong with my code after all - it was the program I was using to view the gif! Internet explorer is a bad idea guys. Always. Can't believe I forgot that! Found out the computer I was using for the coding had Chrome, opened it in Chrome out of curiosity - and it was fine.
Damn you, IE!
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