mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-30 10:58:31 -05:00
FEATURE: automatic image orientation fix
This commit is contained in:
parent
362adb0498
commit
a52c80e2a8
5 changed files with 15 additions and 2 deletions
|
@ -75,6 +75,8 @@ class Upload < ActiveRecord::Base
|
|||
# deal with width & height for images
|
||||
if FileHelper.is_image?(filename)
|
||||
begin
|
||||
# fix orientation first
|
||||
Upload.fix_image_orientation(file.path)
|
||||
# retrieve image info
|
||||
image_info = FastImage.new(file, raise_on_failure: true)
|
||||
# compute image aspect ratio
|
||||
|
@ -115,6 +117,10 @@ class Upload < ActiveRecord::Base
|
|||
Upload.find_by(url: url) if Discourse.store.has_been_uploaded?(url)
|
||||
end
|
||||
|
||||
def self.fix_image_orientation(path)
|
||||
`convert #{path} -auto-orient #{path}`
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# == Schema Information
|
||||
|
|
|
@ -16,7 +16,7 @@ describe AvatarUploadService do
|
|||
let(:avatar_file) { AvatarUploadService.new(file, :image) }
|
||||
|
||||
it "should have a filesize" do
|
||||
avatar_file.filesize.should == 2290
|
||||
avatar_file.filesize.should > 0
|
||||
end
|
||||
|
||||
it "should have a filename" do
|
||||
|
@ -38,7 +38,7 @@ describe AvatarUploadService do
|
|||
before { FileHelper.stubs(:download).returns(logo) }
|
||||
|
||||
it "should have a filesize" do
|
||||
avatar_file.filesize.should == 2290
|
||||
avatar_file.filesize.should > 0
|
||||
end
|
||||
|
||||
it "should have a filename" do
|
||||
|
|
BIN
spec/fixtures/images/logo-dev.png
vendored
BIN
spec/fixtures/images/logo-dev.png
vendored
Binary file not shown.
Before Width: | Height: | Size: 3.2 KiB After Width: | Height: | Size: 5.3 KiB |
BIN
spec/fixtures/images/logo.png
vendored
BIN
spec/fixtures/images/logo.png
vendored
Binary file not shown.
Before Width: | Height: | Size: 2.2 KiB After Width: | Height: | Size: 2.4 KiB |
|
@ -48,12 +48,19 @@ describe Upload do
|
|||
|
||||
context "#create_for" do
|
||||
|
||||
before { Upload.stubs(:fix_image_orientation) }
|
||||
|
||||
it "does not create another upload if it already exists" do
|
||||
Upload.expects(:find_by).with(sha1: image_sha1).returns(upload)
|
||||
Upload.expects(:save).never
|
||||
Upload.create_for(user_id, image, image_filename, image_filesize).should == upload
|
||||
end
|
||||
|
||||
it "fix image orientation" do
|
||||
Upload.expects(:fix_image_orientation).with(image.path)
|
||||
Upload.create_for(user_id, image, image_filename, image_filesize)
|
||||
end
|
||||
|
||||
it "computes width & height for images" do
|
||||
FastImage.any_instance.expects(:size).returns([100, 200])
|
||||
ImageSizer.expects(:resize)
|
||||
|
|
Loading…
Reference in a new issue