-
Notifications
You must be signed in to change notification settings - Fork 21
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
Support browser screen dimensions parameters #18
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great except for one concern with the caching.
This service is used in core and Akismet, so we need to make sure not to trigger a recache of everything.
Totally not a blocker, but I'd lean towards something like "clip height" or "image_height" for the name of the new parameter. There doesn't seem to be a really good name for it, though, and screen_height
will work for my needs, so I'm happy if you're happy.
public_html/class-mshots.php
Outdated
@@ -104,7 +118,7 @@ public function requeue_snapshot() { | |||
} | |||
memcache_set( $m, $urlkey, 1, 0, 300 ); | |||
|
|||
$requeue_url = self::renderer . "/queue?url=" . rawurlencode( $this->snapshot_url ) . "&f=" . urlencode( $this->snapshot_file ); | |||
$requeue_url = self::renderer . "/queue?url=" . rawurlencode( $this->snapshot_url ) . "&f=" . urlencode( $this->snapshot_file ) . '&screen_width=' . $this->screen_width . '&screen_height=' . $this->screen_height; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to make sure we only update this url if these values are non-defualt so as to avoid re-caching all the old images.
Great point! Addressed.
I agree that My only concern now is how to test this before merging, I couldn't run the whole thing (PHP and Node) locally. Do you have any ideas? |
@alshakero and @deBhal I've made an unsuccessful attempt at running mShots in Docker for a local development environment. Unfortunately I haven't gotten very far, but in case either of you would like to take a look / experiment with it, I've pushed it to a draft PR at: #22 — I'm on rotation next week, so won't have a chance to continue chipping away at it, but feel free to dive in if you have the time or inclination :) |
Nice! I was just thinking that containerising the service might simplify the process a lot (especially testing), but I wasn't sure how hard the containerisation itself would be. |
Thanks @deBhal! It is a little fiddly (and obviously not quite working just yet)... I'm not sure if this would help, but I was thinking over the weekend that maybe adding a docker-compose file and running multiple containers might making things a bit clearer, too. E.g. have a puppeteer service container that exposes port 7777 and runs |
Related to this change, I've put together a similar PR to add a |
3cb9162
to
fb9c438
Compare
I was retesting this PR to and ran into a bit of awkwardness - the Regardless, we can fix it by pulling the |
7e1635e
to
fa6fcc2
Compare
The test failures were being caused by the default css A consequence of that was also having to switch from |
253a7ac
to
d7d6253
Compare
8897604
to
de053c5
Compare
Closing: I merged these changes as part of #31 |
Note: You may prefer to review #31 instead. It includes this PR
Depends on #17, related to p3topS-Ia-p2.
This PR adds the support for
screenWidth
andscreenHeight
params. This allows for screenshotting long/short/wide or whatever dimensions the user needs. Both new params are optional hence backward compatible.The first commit is a failing test on purpose. The follow-up commit is the fix to the failing test (the implementation). I used TDD to make the requirement easier to understand and easier to see that it's backward compatible.
To test
The closest I could get to simulating the deployed version is starting the node server. There is another layer of abstraction in PHP but I couldn't get that running.
npm install
./opt/mshots/public_html/thumbnails/
. By runningsudo mkdir -p /opt/mshots/public_html/thumbnails/
.sudo chmod 777 /opt/mshots/public_html/thumbnails/
). Don't worry, you can delete these after you're done.node lib/mshots.js -p 7000 -n 2
)http://localhost:7000/queue?url=https://wordpress.com/&f=/opt/mshots/public_html/thumbnails/875/8751a27a0b7ea911b1fd202d34602123df995951/7be4fb73894606a68035c8fc9c79cce4.jpg
open /opt/mshots/public_html/thumbnails/875/8751a27a0b7ea911b1fd202d34602123df995951/7be4fb73894606a68035c8fc9c79cce4.jpg
.You should see a default-sized image: 1280x960px.
Now, you can try whatever combination you see fit of these params (
screen_width
,screen_height
,vpw
,vph
) :After every test, to see the image, you can run
Once you're done. Feel free to delete the folders: