Skip to content

Commit 418888c

Browse files
committed
improve ime upload resizing
1 parent 853caf1 commit 418888c

8 files changed

Lines changed: 34 additions & 26 deletions

File tree

Dockerfile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ WORKDIR /rails
1111
ENV RAILS_ENV="production" \
1212
BUNDLE_DEPLOYMENT="1" \
1313
BUNDLE_PATH="/usr/local/bundle" \
14-
BUNDLE_WITHOUT="development"
14+
BUNDLE_WITHOUT="development" \
15+
HTTP_PORT=3001 \
16+
SSL=false
1517

1618
# Install application gems
1719
COPY Gemfile Gemfile.lock ./
@@ -45,4 +47,6 @@ HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
4547

4648
# Start the server by default, this can be overwritten at runtime
4749
EXPOSE 3000
50+
EXPOSE 3001
51+
4852
CMD ["./bin/thrust", "rails", "server"]

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ podman run ... -v /path/on/host/GeoLite2-City.mmdb:/rails/db/GeoLite2-City.mmdb
104104

105105
- `SECRET_KEY_BASE` — Rails secret key (must be set in production)
106106
- `DEVELOPER_LOGIN_ENABLED` — optional local developer login (only enable this in test instances)
107-
- `HTTP_PORT` — HTTP port inside the container (default: 3000)
107+
- `HTTP_PORT` — HTTP port inside the container (default: 3001 for thruster, 3000 for puma)
108108
- `SSL` — set to `true` if your container is running behind a TLS terminating reverse proxy (default: true)
109109
- `MONGO_URL` — MongoDB connection string (default: `localhost:27017`)
110110
- `MONGO_DB` — MongoDB database name (default: 'mapforge_production')
@@ -144,7 +144,7 @@ db/GeoLite2-City.mmdb
144144
### Running the Development Server
145145

146146
```bash
147-
bin/thrust rails server
147+
HTTP_PORT=3001 bin/thrust rails server
148148
```
149149

150150
In development, environment variables (see above) can be set in `.env.development`.

app/assets/stylesheets/modals.css

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
border-width: 2px;
7979
border-style: solid;
8080
border-color: #fff;
81-
margin: 5px;
81+
margin: 0.2rem;
8282
opacity: 0.8;
8383
transition:
8484
opacity 0.3s linear,
@@ -93,6 +93,11 @@
9393
opacity: 1;
9494
}
9595

96+
.map-settings {
97+
margin-top: 0.5rem;
98+
margin-left: 0.3rem;
99+
}
100+
96101
.view-values {
97102
font-family: monospace;
98103
background: var(--color-light-steel-blue);

app/controllers/images_controller.rb

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,13 @@ def upload
5353

5454
# use existing image if already uploaded
5555
unless (img = Image.find_by(public_id: filename))
56+
# https://github.com/mtgrosser/rszr
57+
image = Rszr::Image.load(tempfile.path)
5658
# resize image if it exceeds 1024px
57-
image = MiniMagick::Image.read(tempfile)
5859
if image.width > 1024 || image.height > 1024
59-
image.resize "1024x1024" # Maintains aspect ratio, resizes width to 1024px max
60-
image.quality "75"
61-
tempfile = Tempfile.new([ "resized-", File.extname(uploaded_file.original_filename) ])
62-
image.write(tempfile.path)
60+
image.resize!(1024, 1024, crop: false)
61+
image.save(tempfile.path)
6362
end
64-
6563
uid = Dragonfly.app.store(tempfile, "name" => filename) # name needs to be a string here
6664
img = Image.create!(img_uid: uid, public_id: filename, user: @user)
6765
end

app/views/maps/modals/_settings.haml

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,29 +37,28 @@
3737

3838
- Map::BASE_MAPS.each do |base_map|
3939
- active = (@map_properties[:base_map] == base_map)
40-
4140
- map_image = "base_maps/placeholder.jpg"
4241
- if Rails.application.assets.find_asset("base_maps/#{base_map}.jpg").present?
4342
- map_image = "base_maps/#{base_map}.jpg"
4443
= image_tag(map_image, data: { base_map: base_map, action: "click->map--settings#updateBaseMap" }, class: "layer-preview", loading: 'lazy')
4544

46-
%br
47-
- # Default checkbox state gets set by initSettingsModal()
48-
%span.no-wrap.me-2
49-
%label{ for: "map-terrain"} 3D Terrain:
50-
%input#map-terrain{type: "checkbox", data: { action: "click->map--settings#updateTerrain"} }
45+
.map-settings
46+
- # Default checkbox state gets set by initSettingsModal()
47+
%span.no-wrap.me-2
48+
%label{ for: "map-terrain"} 3D Terrain:
49+
%input#map-terrain{type: "checkbox", data: { action: "click->map--settings#updateTerrain"} }
5150

52-
%span.no-wrap.me-2
53-
%label{ for: "map-hillshade"} Hillshade:
54-
%input#map-hillshade{type: "checkbox", data: { action: "click->map--settings#updateHillshade"} }
51+
%span.no-wrap.me-2
52+
%label{ for: "map-hillshade"} Hillshade:
53+
%input#map-hillshade{type: "checkbox", data: { action: "click->map--settings#updateHillshade"} }
5554

56-
%span.no-wrap.me-2
57-
%label{ for: "map-contours"} Contour lines:
58-
%input#map-contours{type: "checkbox", data: { action: "click->map--settings#updateContours"} }
55+
%span.no-wrap.me-2
56+
%label{ for: "map-contours"} Contour lines:
57+
%input#map-contours{type: "checkbox", data: { action: "click->map--settings#updateContours"} }
5958

60-
%span.no-wrap.me-2
61-
%label{ for: "map-globe"} Globe:
62-
%input#map-globe{type: "checkbox", data: { action: "click->map--settings#updateGlobe"} }
59+
%span.no-wrap.me-2
60+
%label{ for: "map-globe"} Globe:
61+
%input#map-globe{type: "checkbox", data: { action: "click->map--settings#updateGlobe"} }
6362

6463

6564
.feature-section-card

app/views/maps/modals/feature/_edit_ui.haml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
- if @user
7575
%label.btn.btn-blue.p-1.ps-2.pe-2{for: 'marker-image'}
7676
%i.bi.bi-upload
77-
%input.form-control#marker-image.hidden{ type: "file", name: 'marker-image', 'data-action': "input->feature--edit#addUndo change->feature--edit#updateMarkerImage" }
77+
%input.form-control#marker-image.hidden{ type: "file", 'data-action': "input->feature--edit#addUndo change->feature--edit#updateMarkerImage" }
7878
- else
7979
%i.bi.bi-info-circle
8080
Please log in to upload images

spec/features/feature_edit_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@
216216
it "can upload image" do
217217
find("#edit-button-style").click
218218
image_path = Rails.root.join("spec", "fixtures", "files", "mapforge-logo-icon.png")
219+
page.driver.execute_script("document.querySelector('#marker-image').classList.remove('hidden')")
219220
expect(page).to have_selector("#marker-image")
220221
attach_file("marker-image", image_path)
221222

@@ -226,6 +227,7 @@
226227
it "can upload image bigger 1024px" do
227228
find("#edit-button-style").click
228229
image_path = Rails.root.join("spec", "fixtures", "files", "image_large.jpg")
230+
page.driver.execute_script("document.querySelector('#marker-image').classList.remove('hidden')")
229231
expect(page).to have_selector("#marker-image")
230232
attach_file("marker-image", image_path)
231233

-8.73 KB
Loading

0 commit comments

Comments
 (0)