It isn't possible to do this with xs:restriction
as you mention, but you can do this with xs:assert
elements and XPath 2.0 functions.
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="itemimage">
<xs:annotation>
<xs:documentation>Item picture in jpeg or gif format</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:base64Binary">
<xs:attribute name="imgdescription" type="xs:string" use="optional"/>
<!-- Crudely check the base64 string length -->
<xs:assert test="string-length(.) lt 2048"/>
<!-- Matching on the start of a JPEG sequence -->
<xs:assert test="matches(., '/9j/')"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:schema>
Your mileage may vary on how well this works, but it's a start.