Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename images when converting formats #404

Closed
wants to merge 2 commits into from
Closed

Rename images when converting formats #404

wants to merge 2 commits into from

Conversation

jcarlson
Copy link
Contributor

<< new issue based on #403 >>

This should help with situations where a file has multiple versions, and at least one of the versions is of a different format than the master version. This scenario is documented in issue #378 as well as in issue #284 (and possibly others).

Simply pass :rename => true to the existing convert helper method, and the file will be renamed as well as converted. Existing functionality is preserved, i.e., the default is to not rename the image.

When using Fog as the storage provider, you can utilize process :set_content_type to detect the new MIME type and have that relayed to the cloud storage provider.

jcarlson added 2 commits July 16, 2011 18:03
This should help with situations where a file has multiple versions, and at least one of the versions is of a different format than the master version. This scenario is documented in issue #378 as well as in issue #284 (and possibly others).
… name. This allows convert to change the file extension and have the MIME type picked up here, reflecting the new type.
@jcarlson
Copy link
Contributor Author

FYI, without this patch, if you were to call any processing commands after a :convert call, the file would be converted back to it's original format. For example

# assume we are working on a 'pretty_flower.jpg' image
process :convert => :png  #after convert, file retains .jpg extension
process :resize_to_fit => [250,250] #rmagick converts back to a JPG when it writes out the file, due to .jpg extension

There are, of course, other ways to work around this limitation, such as writing a custom processor that just renames the file, but was curious as to anyone else's thoughts.

@bensie
Copy link
Member

bensie commented Jul 17, 2011

This looks good, though I don't like to encourage the use of methods like convert("png", false). Would you mind reworking to have the convert method take an options hash as its second argument?

Also, might you be up for tackling a test here?
https://github.com/jnicklas/carrierwave/blob/master/spec/processing/rmagick_spec.rb#L23

@bensie
Copy link
Member

bensie commented Jul 20, 2011

After testing this locally, I see it breaks a few specs because of undefined local variable or method 'current_path'

Feel free to submit a new pull request that fixes this -- and make sure you run the specs and add any relevant tests for the changes you make! Thanks!

@bensie bensie closed this Jul 20, 2011
@jcarlson
Copy link
Contributor Author

Yes, I will make the mentioned changes...

@kuraga
Copy link
Contributor

kuraga commented May 24, 2012

+1 for this feature! But I think rename option should be true by default!

@MikeMcQuaid
Copy link

Did this feature ever make it into master?

@mhuggins
Copy link

mhuggins commented Sep 1, 2012

+1, is this available in master?

@kevinwmerritt
Copy link

I could use this. Set_content_type does not work after convert => 'jpg'

@ThorKhan
Copy link

+1

1 similar comment
@cgat
Copy link

cgat commented Mar 19, 2013

+1

@shoutsid
Copy link

+1 this should be in master. Makes it so much easier when dealing with different file types from the same upload.

@thiagofm
Copy link
Member

I would LOVE to see somebody fix what's pending here and submit a pull request, anyone? ❤️

@bogn
Copy link

bogn commented Dec 17, 2013

This is a severe issue because as stated already, it's totally hidden and undocumented.

We had convert => 'jpg' as first processor and were relying on the final result to be an actual jpg.

Because uploaded pngs were ultimately not converted to jpgs, those images just caused hours of debugging on IE 8. Because of the header X-Content-Type-Options:nosniff the browser was not allowed to sniff the actual content type (see here why) and thus tried to interpret a png file as a jpg file which it could not do and that way the images didn't appear in that browser.

The issue is 'convert' not being effective when further processors follow. This is completely hidden and the advise from the wiki to override the filename method means the resulting images will always have the desired extension, even if the actual files have a different format. This makes it even less likely this issue is discovered early on.

This should be mentioned in the Readme.md and on the known issues page.

@nashby
Copy link
Contributor

nashby commented Aug 27, 2014

Guys, I create a new pull request #1446. I think it should be default behaviour and we don't need that rename option. What do you think?

@bensie
Copy link
Member

bensie commented Aug 27, 2014

#1446 was just merged, thanks @nashby!!

@miguelpeniche
Copy link

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.