The technique you're looking for is called Don't Repeat Yourself, or DRY. To do apply that to the code you've shown you can amend the HTML to use a combination of common classes, to group elements by behaviour, and data
attributes, to place custom metadata on an element.
From there you can use a single event handler for all elements, with the differences applied through the data attributes. Try this:
jQuery($ => {
$('.switch').on('change', e => {
let $image = $(e.target).closest('div').next('.image');
$image.prop('src', $image.data(e.target.checked ? 'checked' : 'unchecked'));
});
});
img { width: 50px; }
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<h3>First example</h3>
<div>
<input type="checkbox" class="switch">
<label>Checkbox</label>
</div>
<img class="image" src="https://i.imgur.com/dC9QaX4.png" data-checked="https://i.imgur.com/1uN7N7b.png" data-unchecked="https://i.imgur.com/dC9QaX4.png">
<h3>Second example</h3>
<div>
<input type="checkbox" class="switch">
<label>Checkbox</label>
</div>
<img class="image" src="https://i.imgur.com/dC9QaX4.png" data-checked="https://i.imgur.com/1uN7N7b.png" data-unchecked="https://i.imgur.com/dC9QaX4.png">
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…